ios - 如何更改 UITableView 和导航栏之间的高度

标签 ios objective-c uitableview uinavigationbar ios7

通过 Storyboard的更改得到了 UITableViewStyleGroupedUITableViewStylePlain ,发现普通表格 View 的顶部边缘粘在导航栏上,而分组样式的顶部间隙不知何故因为标题 View 。

enter image description here

但是,如图所示,间隙“a”比“b”大,为什么? “a”周围是否有隐藏元素?如何管理这个间隙,使其也能被条形卡住?

间隙“a”和“b”的默认大小是多少?如何使“a”等于“b”,就像“设置”

enter image description here

下面是我的尝试


尝试设置 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;
}

enter image description here


尝试了 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;
}

enter image description here


看起来它们都没有按预期工作,间隙“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/

相关文章:

iphone - 从 nib 文件加载 View 时对其进行动画处理

ios - SSZipArchive 的 C header 中的 "Include of non-modular header inside framework module"

ios - 试图让后台获取工作

ios - AVPLayer + 全屏自定义播放器控件

ios - 使用 sender.tag 更改 UIView 颜色

ios - didDeSelectRowAtIndexPath 没有在 objective-c 中被调用

iphone - 如何删除UITableView中最后一个单元格的最后一个边框?

objective-c - 向 ABPerson 添加可导出属性的任何方法

ios - 如何在 ios 中绘制具有角度和距离的线

iphone - uitableview 中的多个倒数计时器