使用tableView的UITableViewStyleGrouped样式时
它是由两部分组成的,上一个section的footer和下一个section的header。通过以下代码就很明显
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [[UIView alloc]init]; view.frame = CGRectMake(0, 0, ScreenW, 20); UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)]; label.center = CGPointMake(ScreenW/2, 20/2); label.font = [UIFont systemFontOfSize:12]; label.backgroundColor = [UIColor redColor]; label.textAlignment = NSTextAlignmentCenter; [view addSubview:label]; if (section == 0) { label.text = @"最后更新时间:"; }else {
label.text =@"配置信息"; } return view; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view = [[UIView alloc]init]; view.frame = CGRectMake(0, 0, ScreenW, 20); UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)]; label.center = CGPointMake(ScreenW/2, 20/2); label.font = [UIFont systemFontOfSize:12]; label.backgroundColor = [UIColor blueColor]; label.textAlignment = NSTextAlignmentCenter; [view addSubview:label]; return view; }
若想去掉section的footer,仅设置:应将其高度设为比1小很多,但不为0的值,才会有效果
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.001f;
}