2

我正在尝试为我的分组单元格创建我自己的部分标题。当我使用以下代码创建它时,它看起来好像边界已关闭。更具体地说,高度CGRect

在此处输入图像描述

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *header = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 50)] autorelease];
    [header setBackgroundColor:[UIColor clearColor]];

    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width, 18)] autorelease];
    label.textColor = [UIColor redColor];
    label.text = @"SOME TEXT";
    label.backgroundColor = [UIColor clearColor];

    [header addSubview:label];

    return header;
}

知道为什么高度关闭了吗?我错过了什么吗?

4

2 回答 2

3

您是否也tableView:heightForHeaderInSection:按照文档中的描述进行了实施?这应该为您的表返回 50。

于 2012-02-27T21:30:42.200 回答
0

只是好奇你为什么不定义 TableView 类型(分组),在 IB 中设置节标题的属性,然后使用:

- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
于 2012-02-27T21:27:54.030 回答