ios - 隐藏 separatorColor 直到 UITableView 有内容

标签 ios swift uitableview

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

我目前的做法是将它添加到 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()
}

最佳答案

将这一行添加到您的 ViewDidLoad()

self.Eventlisttable.tableFooterView = UIView()

关于ios - 隐藏 separatorColor 直到 UITableView 有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39806649/

相关文章:

iphone - 如何将 NSArray 发送到 Web 服务

ios - 将 NSDictionary 从 json 结果保存到 NSUserDefaults 返回 "attempt to insert non-property list object"错误

ios - NSDateComponent 给我一天递增 1

ios - 尝试使用 NSTimer 并在运行我的应用程序时发现一个奇怪的错误

swift - 如何在 forEach 循环中传递变量函数

ios - 在 Swift TableView 中显示 JSON 数据的问题

iphone - didSelectRowAtIndexPath : nested push animations

ios - 如何使用自动布局基于 webview 内容管理 UITableHeaderView 的高度

ios - 缺少返回 UITableViewCell

ios - 动画停止时如何使动画速度变慢