自从我升级到Xcode9/ Swift 4之后,我的一些UITableViewDelegate方法就不再被调用了
发布于 2017-11-08 06:54:25
从Xcode9/ 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 }
}https://stackoverflow.com/questions/47168747
复制相似问题