当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当前回答
为了以编程方式消除UItableview底部额外的分隔行,只需写下下面两行代码,它就会从UItableview底部删除额外的分隔行。
tableView.sectionFooterHeight = 0.f;
tableView.sectionHeaderHeight = 0.f;
这招对我一直很管用,你自己试试。
其他回答
我想扩展一下我的回答:
简单地添加高度为0的页脚就可以了。(在SDK 4.2, 4.4.1上测试)
- (void) addFooter
{
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
[self.myTableView setTableFooterView:v];
}
或者更简单——在你设置tableview的地方,添加这一行:
//change height value if extra space is needed at the bottom.
[_tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)]];
或者更简单——简单地删除任何分隔符:
[_tableView setTableFooterView:[UIView new]];
再次感谢wkw:)
你可以在最后添加一个空的页脚,它会隐藏空的单元格,但它也会看起来很难看:
tableView.tableFooterView = UIView()
有一个更好的方法:在表格视图的末尾添加1点线作为页脚,空单元格也将不再显示。
let footerView = UIView()
footerView.frame = CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1)
footerView.backgroundColor = tableView.separatorColor
tableView.tableFooterView = footerView
在Swift中(我使用4.0),你可以通过创建一个自定义UITableViewCell类来实现这一点,并覆盖setSelected方法。然后分隔符将全部插入到0。(我的主类与表视图有一个清晰的背景)颜色。
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// eliminate extra separators below UITableView
self.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
只需添加这个代码(Swift)。
tableView.tableFooterView = UIView()
Swift 3 /Swift 4 /Swift 5 +,非常简单
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
//MARK:- For Hiding the extra lines in table view.
tableView?.tableFooterView = UIView()
}
OR
override func viewDidLoad(_ animated: Bool) {
super.viewDidLoad(animated)
//MARK:- For Hiding the extra lines in table view.
tableView?.tableFooterView = UIView()
}