ios - 自定义表格标题部分

标签 ios uitableview

我有一个带有组样式表的应用。

我尝试自定义表头部分:

- (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;
}

但是我的标题关闭了单元格:

enter image description here

为什么?

最佳答案

您还需要实现 tableView:heightForHeaderInSection: 来为节标题设置正确的高度。参见 the Apple docs

关于ios - 自定义表格标题部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9738598/

相关文章:

swift - 将数据从 UIViewController 发送到 UIView

ios - 从键为空字符串的 NSDictionary 中删除值

ios - estimatedHeightForRowAtIndexPath 的错误滚动位置

ios - 根据indexPath.section和indexPath.row判断多维结构的cell类型

ios - 如何更新我的自定义单元格 subview 的数据和 View ?

ios - 在 TabBarController 中使用相同的 ViewController 和 TableView

c# - Xamarin iOS ViewCellRenderer

php - Google Firebase 通知在控制台上工作但不在 API 上工作

ios - 如何通过 touchesMoved 方法获取用于在场景 View 上绘制 UIBezierpath 的准确 CGpoint?

ios - UITableView 和 NSFetchedController 委托(delegate)从未被调用