【问题标题】:Height of tableHeaderView seems to be 0tableHeaderView 的高度似乎为 0
【发布时间】:2010-03-16 06:58:43
【问题描述】:

我试图覆盖第二个 tableHeaderView。但是似乎heightForHeaderInSection方法中它的高度似乎为0。无法解释,我是否必须将其放入iVar中,因为在viewForHeaderInSection中我可以毫无问题地设置视图。

 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0)
    return @"Adding a new list";
else
    return @"Other lists";

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

if(section == 0) {
    return tableView.tableHeaderView;
} else {
    UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)] autorelease];
    view.backgroundColor = [UIColor redColor];

    return view;
}

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 0)
    return tableView.tableHeaderView.frame.size.height;
else
    return 30;
}

【问题讨论】:

    标签: iphone uitableview grouped-table


    【解决方案1】:

    我认为您混淆了表格标题和每个部分的标题,它们是不同的。没有“第二个 tableHeaderView”,UITableView 有一个tableHeaderView,然后依赖viewForHeaderInSectionheightForHeaderInSection 方法为每个部分放置自定义标题视图,否则您只需使用titleForHeaderInSection 将文本放置在那里.

    【讨论】:

    • 好的,但我的方法是使用不同的节标题。第一个应该使用文本,第二个应该使用文本 + 一个 uibutton。
    • 我不确定你是否可以混合使用 titleForHeaderInSection 和 viewForHeaderInSection,如果你想使用 viewForHeaderInSection,你必须为每个部分创建自定义视图。
    • 您可以从您自己的自定义viewForHeaderInSection 中调用titleForHeaderInSection。因此,您仍然可以使用它来管理您的标题。但是这里没有魔法,你必须自己将这两种方法缝合在一起。如果代理设置为提供标题视图,它不会询问标题。
    猜你喜欢
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2018-03-05
    • 1970-01-01
    • 2012-01-05
    • 2019-01-07
    相关资源
    最近更新 更多