1.在StoryBoard上创建2个tableView,并用autolayout约束。
2.在ViewController上拖进来。
@property (weak, nonatomic) IBOutlet UITableView *leftTableView;
@property (weak, nonatomic) IBOutlet UITableView *rightTableView;
3.实现代理方法;
重点:区分tableView的方法就是用对象比对的方法,传进来的tableView是哪个tableview。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([tableView isEqual:self.leftTableView]) {
return 5;
} else if ([tableView isEqual:self.rightTableView]) {
return 3;
}
return 0;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if ([tableView isEqual:self.leftTableView]) {
static NSString *identifier = @"leftCell";
...
return letfCell; } else if ([tableView isEqual:self.rightTableView]) {
static NSString *identifier = @"rightCell";
...
return rightCell;
}
return nil;
}
--end