Multiple UITableViews on one UIView

后端 未结 3 1383
臣服心动
臣服心动 2020-11-29 05:26

I need to have two UITableViews on one UIView. I can make it work with one, here is the code:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableV         


        
相关标签:
3条回答
  • 2020-11-29 06:04

    This sample code might help you...

    0 讨论(0)
  • 2020-11-29 06:16

    so you need some way to tell the two tableViews apart--you could either set the "tag" property to different values, or have a property on your view controller that points to each view

    @property (nonatomic, retain) IBOutlet UITableView *tableView1;
    @property (nonatomic, retain) IBOutlet UITableView *tableView2;
    

    then hook these up to each view in interface builder...

    then in your view controller methods you can do

    (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        if (tableView == self.tableView1) {
            return 37;
        } else if (tableView == self.tableView2) {
            return 19;
        } else {
            // shouldn't get here, use an assert to check for this if you'd like
        }
    }
    
    0 讨论(0)
  • 2020-11-29 06:18

    Probably the easiest way of implementing this is to have two delegate and data source classes, one for each table view. That would reduce the number of if (tableview == tableview1) occurances in the view controller code.

    0 讨论(0)
提交回复
热议问题