Height of tableHeaderView seems to be 0

老子叫甜甜 提交于 2019-12-11 07:59:24

问题


I tried to override the second tableHeaderView. But it seems that the height of it in the method heightForHeaderInSection seems to be 0. Can't explain it, do I have to put it in a iVar because in the viewForHeaderInSection I can set the view without any problems.

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

回答1:


I think you are confusing the table header and the header for each section, they are different. There is no "second tableHeaderView", a UITableView has one tableHeaderView and then depends on the viewForHeaderInSection and heightForHeaderInSection methods to place custom header views for each section, otherwise you just use titleForHeaderInSection to place text there.



来源:https://stackoverflow.com/questions/2450957/height-of-tableheaderview-seems-to-be-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!