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

如何移除这些单元格?


当前回答

Swift 4.0扩展

只是一个小扩展的故事板:

extension UITableView {
    @IBInspectable
    var hideSeparatorForEmptyCells: Bool {
        set {
            tableFooterView = newValue ? UIView() : nil
        }
        get {
            return tableFooterView == nil
        }
    }
}

其他回答

只需添加一个视图,以所需的分隔符颜色为背景色,宽度为100%,高度为1px,位置为x0 y-1到你的tableViewCell。确保tableViewCell不剪辑子视图,而应该是tableView。

所以你得到了一个绝对简单的和工作的分离只在现有的单元之间没有任何hack每个代码或IB。

注意:在垂直顶部反弹时,第一个分隔符会出现,但这应该不是问题,因为这是iOS的默认行为。

快捷便捷的Swift 4方式。

override func viewDidLoad() {
     tableView.tableFooterView = UIView(frame: .zero)
}

如果你有静态单元格。您也可以从检查器窗口关闭分隔符。(如果你需要分隔符,这是不可取的。在这种情况下,使用上述方法)

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

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

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

迅速:

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.tableFooterView = UIView()
    }