ios - 覆盖函数错误!方法不会覆盖其父类(super class)中的任何方法
<p><pre><code>override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
}
override func supportedInterfaceOrientations() -> Int {
}
</code></pre>
<p>这里我有一个错误。它说</p>
<blockquote>
<p>Method does not override any method from its superclass. </p>
</blockquote>
<p>多次出现,无法修复。</p>
<p>你知道吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>错误即将到来,因为您的方法签名与实际签名不同。您应该使用确切的方法签名进行覆盖(您应该使用 Xcode 中提供的自动完成功能或引用文档)</p>
<p> <a href="https://developer.apple.com/reference/uikit/uiresponder/1621142-touchesbegan" rel="noreferrer noopener nofollow">Touches Began</a> :</p>
<pre><code>override func touchesBegan(_ touches: Set<UITouch>,
with event: UIEvent?)
{
}
</code></pre>
<p>在 Swift 3 中 <a href="https://developer.apple.com/reference/uikit/uiviewcontroller/1621435-supportedinterfaceorientations" rel="noreferrer noopener nofollow">supportedInterfaceOrientations</a>不再是方法,而是计算属性,所以它的签名变成:</p>
<pre><code>override var supportedInterfaceOrientations : UIInterfaceOrientationMask
{
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 覆盖函数错误!方法不会覆盖其父类(super class)中的任何方法,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39947160/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39947160/
</a>
</p>
页:
[1]