iOS 一个ViewController上显示2个tableView的方法


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM