Tvd*_*Tvd 5 objective-c uitableview ios
在视图控制器中,我只有一个UITableView.在IB中,我将Header&Footer高度设为1,并且还添加了以下代码,但是在第1个单元格之上,它们有很多标题空间.我想摆脱那个空间.甚至滚动条也从第一个单元格开始,而不是从顶部开始.
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
CGFloat height = 0.0001;
return height;
}
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
CGFloat height = 0.0001;
return height;
}
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// Create Empty View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width,
[self tableView:self.visitorlistsTv heightForHeaderInSection:section]) ];
return view;
}
-(UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
// Create Empty View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width,
[self tableView:self.visitorlistsTv heightForFooterInSection:section]) ];
return view;
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,页脚部分被隐藏.但是也无法隐藏标题.
查看解决方案的其他链接我还在View中添加了TableView,为tableview添加了约束,但仍然是标题部分仍然是它们的.
我哪里错了?如何摆脱它?
如果您尝试删除上方的空格,请UITableView
尝试更改其contentInset
属性,而不是使用小的自定义标题height
:
self.tableView.contentInset = UIEdgeInsetsMake(-20.0f, 0.0f, 0.0f, 0.0f);
Run Code Online (Sandbox Code Playgroud)
您可能需要调整第一个数字以将其调整到特定的视图场景.
了解这也是一种解决方法(源代码),但它比创建自定义表视图头更干净.
归档时间: |
|
查看次数: |
7053 次 |
最近记录: |