ios - 错误 Swift 方法不会覆盖其父类(super class)中的任何方法

标签 ios swift error-handling superclass

override func supportedInterfaceOrientations() -> Int {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
    } else {
        return Int(UIInterfaceOrientationMask.All.rawValue)
    }
}

所以我正在编写教程并完成了它,当我更新到 xcode 7 时,我的所有代码都充满了错误。

在上面的文章中,我收到错误“方法没有覆盖其父类(super class)中的任何方法”,但是当我删除覆盖时,我收到此错误:方法“supportedInterfaceOrientations()”与 Objective-C 选择器“supportedInterfaceOrientations”冲突使用来自具有相同 Objective-C 选择器的父类(super class)“UIViewController”的方法“supportedInterfaceOrientations()”

我一直在研究,但我对编程很陌生,这里的很多答案我都不太理解,无法应用于我的情况。

谢谢

最佳答案

它不再返回 Int。新方法签名需要返回一个 UIInterfaceOrientationMask

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .phone {
        return UIInterfaceOrientationMask.allButUpsideDown
    } else {
        return UIInterfaceOrientationMask.all
    }
}

关于ios - 错误 Swift 方法不会覆盖其父类(super class)中的任何方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33788038/

相关文章:

ios - Swift 中的 UITextStorageDirection 和 UITextLayoutDirection 枚举是什么?

json - alamofireobjectmapper requestObject 无法做出正确的请求和映射

ios - Xib 导出 View swift 变为 nil

ios - 隐藏键盘会破坏 TableView 的 segue

ios - 每当激活带有链接的 TextView 时,应用程序就会崩溃并出现画外音

ios - 如何等待RACSequence完成它的任务

php - Bugsnag 没有显示漂亮的错误页面

javascript - 如何处理 Promise 模式中异步调用之前发生的错误?

ios - RxMoya 网络和服务错误处理在同一函数中

ios - 我正在尝试用用户列表填充 TableView ,但 TableView 不会加载任何内容