xcode 覆盖 func 错误!方法不会覆盖其超类中的任何方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39947160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:25:56  来源:igfitidea点击:

Override func Error! Method does not override any method from its superclass

iosxcodeios10

提问by user6083214

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
}

override func supportedInterfaceOrientations() -> Int {
}

Here I have an error. It says

这里我有一个错误。它说

Method does not override any method from its superclass.

方法不会覆盖其超类中的任何方法。

This comes multiple times, I can't fix it.

多次出现这种情况,我无法解决。

Do you know something about it?

你知道吗?

回答by Midhun MP

The error is coming because your method signature is different than the actual ones. You should use the exact method signature for overriding (Either you should use auto-complete feature provided in Xcode or refer the documentation)

错误即将到来,因为您的方法签名与实际签名不同。您应该使用确切的方法签名进行覆盖(您应该使用 Xcode 中提供的自动完成功能或参考文档)

Touches Began:

接触开始

override func touchesBegan(_ touches: Set<UITouch>, 
         with event: UIEvent?)
{
}

In Swift 3 supportedInterfaceOrientationsis no longer a method, it's a computed property, so it's signature becomes:

在 Swift 3 中,supportedInterfaceOrientations不再是一个方法,它是一个计算属性,所以它的签名变成:

override var supportedInterfaceOrientations : UIInterfaceOrientationMask
{
}