要自定义TableView的sectionHeader view(sectionFooter同理),需要实现UITableViewDelegate如下的两个方法:
//自定义section的头部
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 40)];//
//add your code behind
return view;
}
//自定义section头部的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 120.0;
}
注意,UITableView的style:为grouped时,section header会和cell一样划出界面;为plain的时,section header在当前section的cell没有全部滑出界面时,section一直会停留在tableView的顶部。