【发布时间】:2013-09-24 20:17:03
【问题描述】:
通过故事板的更改获得UITableViewStyleGrouped和UITableViewStylePlain,发现普通表格视图的顶部边缘粘在导航栏上,而分组样式的顶部间隙不知何故由于标题视图。
但是,如图所示,间隙“a”大于“b”,为什么呢? “a”周围是否有任何隐藏元素?如何管理这个差距,以便它也可以被 bar 卡住?
间隙“a”和“b”的默认大小是多少?如何让“a”等于“b”,比如“设置”
下面是我的试用
尝试设置heightForHeaderInSection: 和viewForHeaderInSection:,如下所示
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView * header = [[UIView alloc] init];
header.backgroundColor = [UIColor redColor];
[self.view addSubview:header];
return header;
}
试过heightForFooterInSection: 和viewForFooterInSection:,如下所示
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView * footer = [[UIView alloc] init];
footer.backgroundColor = [UIColor yellowColor];
[self.view addSubview:footer];
return footer;
}
看起来它们都没有按预期工作,间隙“a”始终存在并且没有改变。
奇怪的是,页眉和页脚的高度仍然存在,看起来是最小高度,
即使将它们的高度设置为零。
【问题讨论】:
-
我遇到了同样的问题。我的结论是,如果您返回 0,则默认显示具有默认高度的标准空部分标题。它甚至不会调用标题视图和标题文本的方法。如果您返回不同的值,例如0.5,然后它调用标题视图和文本方法并显示具有指定高度的正确节标题。
标签: ios objective-c uitableview uinavigationbar ios7