当我设置一个有4行的表格视图时,在填充行的下面仍然有额外的分隔行(或额外的空白单元格)。

如何移除这些单元格?


当前回答

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()
}

其他回答

我想扩展一下我的回答:

简单地添加高度为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:)

我只是在ViewDidLoad函数中添加了这一行,问题就解决了。

tableView.tableFooterView = [[UIView alloc] init]; 

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()
}

你可以在最后添加一个空的页脚,它会隐藏空的单元格,但它也会看起来很难看:

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

您可以删除空行分隔符,只需添加脚注的小高度

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 0.01
}