当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当前回答
如果你只有一个部分,那么最快最简单的方法就是将表格视图样式从“普通”设置为“分组”。(见图片)
如果你有更多的部分,你可能需要将标题高度设置为0(这取决于你/你的客户/你的项目经理的口味)
如果你有更多的部分,并且不想弄乱页眉(即使在最简单的情况下它只是一行),那么你需要设置一个UIView作为页脚,正如它在前面的回答中解释的那样)
其他回答
Swift适用于:
tableView.tableFooterView = UIView()
我很幸运地实现了一个被接受的答案(iOS 9+, Swift 2.2)。我尝试着执行:
self.tableView.tableFooterView = UIView(frame: .zero)
然而,对我的tableView没有任何影响-我相信这可能与我使用UITableViewController的事实有关。
相反,我只需要重写viewForFooterInSection方法(我没有在其他地方设置tableFooterView):
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView(frame: .zero)
}
这对于具有单个section的tableView来说效果很好(如果有多个section,则需要指定最后一个)。
试试这个
针对Objective C
- (void)viewDidLoad
{
[super viewDidLoad];
// This will remove extra separators from tableview
self.yourTableView.tableFooterView = [UIView new];
}
为迅速
override func viewDidLoad() {
super.viewDidLoad()
self.yourTableView.tableFooterView = UIView()
}
试试这个
self.tables.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 10.0f)];
改进J. Costa的解决方案:你可以通过下面这行代码对表进行全局更改:
[[UITableView appearance] setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
在第一个可能的方法中(通常在AppDelegate中,在:application:didFinishLaunchingWithOptions: method)。