- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if(section != 0) {
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
view.backgroundColor = [UIColor redColor];
return view;
} else {
return tableView.tableHeaderView;
}
Run Code Online (Sandbox Code Playgroud)
}
这是我对viewForHeaderInSection的实现,但无论我做什么帧,它总是向我显示相同的红框.你看到我的代码有什么问题吗?
图片:

更新:
嗯,现在我的红色区块更高,但我的第一个桌面现在以某种方式隐藏了.第一个是使用titleForHeaderInSection实现的.我以为我只是实现tableHeader高度的高度,但这不起作用
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 1)
return 30;
else
return tableView.tableHeaderView.frame.size.height;
}
Run Code Online (Sandbox Code Playgroud)