通过 Storyboard的更改得到了 UITableViewStyleGrouped
和 UITableViewStylePlain
,发现普通表格 View 的顶部边缘粘在导航栏上,而分组样式的顶部间隙不知何故因为标题 View 。
但是,如图所示,间隙“a”比“b”大,为什么? “a”周围是否有隐藏元素?如何管理这个间隙,使其也能被条形卡住?
间隙“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”始终存在并且没有改变。
奇怪的是,页眉和页脚的高度仍然存在,看起来是最小高度,
即使将其高度设置为零。
最佳答案
不确定为什么发生您的问题,但有一种解决方法可以将分组的表格 View “卡在”导航栏的底部:
CGFloat myInset = *HEIGHT OF GAP A*
self.tableView.contentInset = UIEdgeInsetsMake(-myInset, 0, 0, 0);
关于ios - 如何更改 UITableView 和导航栏之间的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18991240/