【问题标题】:Custom table header section自定义表头部分
【发布时间】:2012-03-16 13:58:18
【问题描述】:

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

我尝试自定义表头部分:

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

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

为什么?

【问题讨论】:

  • 仅供参考,您可以使用故事板拖出 UIView 并将其放置为表头。然后将其分配给 IBOutlet。

标签: ios uitableview


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    发生这种情况是因为您的标头高度设置为 0,直到您覆盖另一个委托:

    – tableView:heightForHeaderInSection:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 2013-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多