隐藏separatorColor直到UITableView具有内容

时间:2016-10-01 12:34:00

标签: ios swift uitableview

如何从separatorStyle隐藏UITableView,直到表格中有内容为止。换句话说,我只想在表格有内容时显示分隔线。

我目前正在这样做的方法是在cellForRowAtIndexPath方法中添加它,我不确定它是否是正确的位置,因为它每次都是新的行是输入。

有没有更好的方法来实现它?有什么建议? cellForRowAtIndexPath是个不好的地方吗?

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// code...
    myTable.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
    myTable.separatorColor = UIColor.myMediumGrayColor()
// code...
}
编辑:感谢@ Hems Moradiya 的答案,以下是我所做的工作。我将代码移动到viewDidLoad方法,如下所示。

override func viewDidLoad() {
    super.viewDidLoad()

    self.myTable.tableFooterView = UIView()
    myTable.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
    myTable.separatorColor = UIColor.myMediumGrayColor()
}

1 个答案:

答案 0 :(得分:2)

ViewDidLoad()

中添加此行
self.Eventlisttable.tableFooterView = UIView()
相关问题