简体   繁体   English

UIVIevController覆盖

[英]UIVIevController overriding

I have some troubles (error: Method does not override any method from its superclass) with overriding UIVC method, what am I doing wrong? 我在重写UIVC方法时遇到了一些麻烦(错误:方法未从其超类重写任何方法) ,我在做什么错?

Code example with supportedInterfaceOrientation, which doesn`t cause error, but still not overriding and not working. 具有supportInterfaceOrientation的代码示例,它不会引起错误,但是仍然不能覆盖并且无法正常工作。

func supportedInterfaceOrientations() -> UIInterfaceOrientationMask{
return UIInterfaceOrientationMask(rawValue:(UIInterfaceOrientationMask.portrait.rawValue | UIInterfaceOrientationMask.landscape.rawValue))}

Screenshot problem enter image description here 屏幕截图问题,请在此处输入图片说明

supportedInterfaceOrientations is a computed property, not a function: supportedInterfaceOrientations是一个计算的属性,而不是一个函数:

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations

so error is correct - there is no such function in superclass. 所以错误是正确的-在超类中没有这样的功能。

Replace func with var and () -> with : var() ->替换func :

The new versions of the Xcode the method have changed. Xcode的新版本方法已更改。 Now it's a variable that you can override. 现在,这是一个可以覆盖的变量。

@available(iOS 6.0, *)
open var supportedInterfaceOrientations: UIInterfaceOrientationMask { get }

It's a property. 这是财产。 Swift override: 快速覆盖:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    get {
        return UIInterfaceOrientationMask.all
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM