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

标签 ios swift

我尝试在viewcontroller中实现两种方法

override func shouldAutorotate() -> Bool {
    return false
}

override func supportedInterfaceOrientations() -> Int {
    return UIInterfaceOrientation.Portrait.rawValue
}

但我不能,因为我收到第二种方法的错误,上面写着

Method does not override any method from its superclass

如果我删除 override 关键字,我还会收到一条错误消息

enter image description here

我该怎么办?

最佳答案

Swift 2.0 的新语法:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.Portrait
}

检查Documentation了解更多信息。

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

相关文章:

ios - 有没有办法在 iOS 的 UITextView 中调整文本

iphone - Facebook iOS 应用程序的主菜单使用什么库?

ios - 变换后更新点

swift - Cocoa SCNetworkInterface 获取媒体子类型

iphone - 在应用程序购买Apple ID登录警报中听“取消”按钮?

ios - 基于 StatusBar 的方向检测未命中

swift - 涂上 :only generating unit test results not the UI tests

ios - SwiftUI 中的自定义模式转换

ios - 在按钮上设置自定义属性

ios - 线程 1 : Signal SIGABRT (Could not cast value of type to 'SignInViewController' to 'AWSCognitoIdentityPasswordAuthentication' )