当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。
如何移除这些单元格?
当前回答
为了以编程方式消除UItableview底部额外的分隔行,只需写下下面两行代码,它就会从UItableview底部删除额外的分隔行。
tableView.sectionFooterHeight = 0.f;
tableView.sectionHeaderHeight = 0.f;
这招对我一直很管用,你自己试试。
其他回答
试试这个。这招对我很管用:
- (void) viewDidLoad
{
[super viewDidLoad];
// Without ARC
//self.tableView.tableFooterView = [[[UIView alloc] init] autorelease];
// With ARC, tried on Xcode 5
self.tableView.tableFooterView = [UIView new];
}
为了以编程方式消除UItableview底部额外的分隔行,只需写下下面两行代码,它就会从UItableview底部删除额外的分隔行。
tableView.sectionFooterHeight = 0.f;
tableView.sectionHeaderHeight = 0.f;
这招对我一直很管用,你自己试试。
我很幸运地实现了一个被接受的答案(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,则需要指定最后一个)。
我只是在ViewDidLoad函数中添加了这一行,问题就解决了。
tableView.tableFooterView = [[UIView alloc] init];
我添加了这个小的tableview扩展,有助于整个
extension UITableView {
func removeExtraCells() {
tableFooterView = UIView(frame: .zero)
}
}