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
