uitableview的一些小细节

  • tableView的group样式的section高度由以下两个方法返回的高度决定:
    • - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    • - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

tableView是不会主动调用这两个方法的,唯有实现了
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
才会调用第一个方法。实现
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
才会调用第二个方法.
当需要设置间距为0时,一般设置第一和第二方法的返回值为CGFLOAT_MIN(设置为0可能不起作用)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}

转载请注明出处:@lzx1995