1、在使用tableView中有一个重要的属性:indexPath,初学者往往不能准确的理解其含义,所以详解如下:
tableView 有2个style,分别为plain和grouped。
indexPath有2个属性:section和row,分别指在一个tableView里面的组跟行。
其中plain里的section值为1,表格从一个行row为0,依次加1。
在grouped中,section跟row的数值如下图所示:
2、点击事件的方法使用注意
在创建点击tableView里的单元格触发的事件时,有2种经常混淆或者弄错的方法
a、-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
b、 -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
超级像有木有!!!博主就因为这个傻掉过几分钟= =
区别点: a的方法点击后立即执行方法内的事件。
b的方法在第二次点击其他单元格后,触发第一次点击所在单元格的事件(在这个方法中,当第一次单元格被选中时处于选中状态,不能再次点击,需点击不同单元格)。切记!!!!
3、在一个view里面使用2个或多个tableView,如何加载数据源方法
实现方法: 在加载数据源方法内,当有2个tableView时用if语句,分别加载进去。
当有多个tableView时用switch语句判断。
例:创建 tableView1 、 tableView2:
//返回一组内有多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == tableView1) {//tableView1返回5行
return 5;
}else{ //tableView2返回10行
return 10;
}
}