【问题标题】:What's wrong with my code? Method cannot be an @objc我的代码有什么问题?方法不能是@objc
【发布时间】:2017-08-01 13:50:35
【问题描述】:

我的代码有什么问题?我一直收到这个错误,我不知道为什么它说方法不能是 @objc 覆盖,因为参数 2 的类型不能在 Objective-C 中表示。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.

    let vc = segue.destinationViewController as! MovieViewController
    if let indexPath = self.tableView.indexPathForSelectedRow{
        let item = TableData[indexPath.row]
        vc.senddMovie = item
    }
}

【问题讨论】:

  • 您在哪一行收到此错误
  • 在覆盖函数准备的第 1 行
  • 你把@objc放在你上面的班级哪里?
  • 您使用的是什么版本的 Xcode?我可以找到消息 因为参数 2 的类型不能在 Objective-C 中表示 仅在 Swift 2 中。
  • 您使用的是什么版本的 Xcode?在 8.2.1 中,segue.destinationViewController 现在是 segue.destination,所以我怀疑您使用的是旧版本。

标签: swift


【解决方案1】:

这是因为“任何?”在函数签名中。它是一种 swift only 类型,不能桥接到 Objective-C。

查看讨论该问题的答案: https://stackoverflow.com/a/26366289/4264079

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    相关资源
    最近更新 更多