【发布时间】:2018-04-20 11:50:18
【问题描述】:
自从我升级到 Xcode 9 / Swift 4 后,我的一些 UITableViewDelegate 方法不再被调用
【问题讨论】:
标签: xcode uitableview swift4 xcode9
自从我升级到 Xcode 9 / Swift 4 后,我的一些 UITableViewDelegate 方法不再被调用
【问题讨论】:
标签: xcode uitableview swift4 xcode9
从 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 }
}
【讨论】: