我有一个带有组样式表的应用。
我尝试自定义表头部分:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
UILabel *userName = [[UILabel alloc] initWithFrame:CGRectMake (0,0,200,30)];
if (section != 0)userName.text = @"lalala";
[userName setFont:[UIFont fontWithName:@"HelveticaNeue" size:20]];
[headerView addSubview:userName];
[headerView setBackgroundColor:[UIColor clearColor]];
[userName setBackgroundColor:[UIColor clearColor]];
return headerView;
}
但是我的标题关闭了单元格:
为什么?
最佳答案
您还需要实现 tableView:heightForHeaderInSection:
来为节标题设置正确的高度。参见 the Apple docs
关于ios - 自定义表格标题部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9738598/