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