【问题标题】:willSelectRowAt and didSelectRowAt not called anymore since Xcode 9 / Swift 4willSelectRowAt 和 didSelectRowAt 自 Xcode 9 / Swift 4 起不再调用
【发布时间】:2018-04-20 11:50:18
【问题描述】:

自从我升级到 Xcode 9 / Swift 4 后,我的一些 UITableViewDelegate 方法不再被调用

【问题讨论】:

    标签: xcode uitableview swift4 xcode9


    【解决方案1】:

    从 Xcode 9 / Swift 4 开始,所有 Objective-C 方法都应标记为 @objc。编译器在识别应该应用它的位置方面做了合理的工作,但是它没有弄清楚继承。例如:

    class Delegate: NSObject, UITableViewDelegate {
    }
    
    class SuperDelegate: Delegate {
        override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { return indexPath }
    }
    

    这不会产生任何警告、崩溃或构建错误。但是,在您添加 @objc 之前,您的线路不会被调用:

    @objc class SuperDelegate: Delegate {
        override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { return indexPath }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      相关资源
      最近更新 更多