2 tableview on a single view

前端 未结 2 993
深忆病人
深忆病人 2020-12-15 14:22

I need an example or explanations of how to populate 2 table views which are on the same view. I need to understand the \"cellForRowAtIndexPath\" method, could someone provi

2条回答
  •  太阳男子
    2020-12-15 15:02

    IMO the cleanest solution would be to have one controller for each tableview.

    radios_tv would call it own delegate's method, while presets_tv calls it own.

    edit

    if you use one controller for n tableview, you will have to use if-statemenst in many places, in

    • – numberOfSectionsInTableView:
    • – tableView:numberOfRowsInSection:
    • – tableView:titleForHeaderInSection:

    basically in all UITableViewDatasource-Protocol methods that you will need to implement.

    So if you need to change something, you have to change it in many places.

    If you use one controller class for one tableview, you won't have to check at all.

    1. write a controller class for every tableview, make it conforming to the UITableViewDatasource protocol
      • implement the protocol methods you will need. at least
        • – numberOfSectionsInTableView:,
        • – tableView:numberOfRowsInSection:,
        • – tableView:cellForRowAtIndexPath:
    2. call -setDataSource:for every tableview to an object of the right controller class

    I think, it was shown in one of the WWDC 2010 videos. I am not sure, but I guess it was Session 116 - Model-View-Controller for iPhone OS.

    edit

    I wrote an example code: http://github.com/vikingosegundo/my-programming-examples

提交回复
热议问题