我试图覆盖第二tableHeaderView。但似乎它在方法的高度heightForHeaderInSection似乎是0.不能解释它,我必须把它放在一个伊瓦因为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;
}
有帮助吗?

解决方案

我想你混淆表头以及用于每个部分的报头,它们是不同的。有没有“第二tableHeaderView”,一个UITableView有一个tableHeaderView,然后依赖于viewForHeaderInSectionheightForHeaderInSection方法将每个部分自定义标题的观点,否则你只是用titleForHeaderInSection在那里放置文本。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top