tableHeaderView的高度似乎为0 [英] Height of tableHeaderView seems to be 0

查看:202
本文介绍了tableHeaderView的高度似乎为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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.

这篇关于tableHeaderView的高度似乎为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆