IOS UI学习 UITableView ----- UITableViewDelegate
第一篇是关于UITableView的简单介绍以及UItableView 的 UITableViewDatasource 协议方法
那么这一篇这是关于 UITableView 的另一个代理 UITableViewDelegate的一些协议方法
设置每一个cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// indexPath.section,根据分组进行更精确的配置
return 90.0;
}
设置每一个section的header的高度
设置每个分组中header的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}
设置每一个setion的footer的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
// indexPath.section,根据分组进行更精确的配置
return 55;
}
设置每一个cell的自定制header
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// 自定义的Header
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
view.backgroundColor = [UIColor redColor];
return view;
}
设置每一个cell的自定制footer
设置自定义footer
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
// 自定义的Footer
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
view.backgroundColor = [UIColor yellowColor];
return view;
}
cell被选择时调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//indexPath section row indexPath.section indexPath.row
[_selectCell addObject:indexPath];
NSLog(@"选择:%@",indexPath);
}
cell被取消选择时调用
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"取消选择:%@",indexPath);
[_selectCell removeObject:indexPath];
}
未完待续

浙公网安备 33010602011771号