问题描述
我尝试覆盖第二个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
,然后依靠viewForHeaderInSection
和heightForHeaderInSection
方法为每个节放置自定义标题视图,否则,您只需使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!