【问题标题】:Extend UIViewController to implement tableView(_ tableView: willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)扩展 UIViewController 实现 tableView(_tableView: willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
【发布时间】:2018-06-23 22:38:03
【问题描述】:

我想更改我不拥有的ViewController 的单元格的设计。所以我的想法是这样的扩展:

extension NotMyViewController {
    public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cell.textLabel?.font = UIFont(name: "DesignersChoice", size: 12)
    }
}

但是这个函数永远不会被调用。有什么想法可以让我们的设计师开心吗?

【问题讨论】:

  • “我不拥有”是什么意思?你如何与 ViewController 对话?
  • 查看tableView delegate

标签: ios swift uitableview cocoa-touch


【解决方案1】:

确认你的班级使用UITableViewDelegate协议

extension NotMyViewController: UITableViewDelegate {
    public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cell.textLabel?.font = UIFont(name: "DesignersChoice", size: 12)
    }
}

也让 NotMyViewController 作为你的 tableView 的委托

【讨论】:

    【解决方案2】:

    使用cellForRowAtIndex 方法。在该方法中写下一行:-

    cell.textLabel?.font = UIFont(name: "DesignersChoice", size: 12)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-20
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多