对不起,我不太擅长解释这些东西。基本上我有以下功能来处理远程控制事件。
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
override func remoteControlReceivedWithEvent(event: UIEvent) {
if event.type == UIEventType.RemoteControl {
if event.subtype == UIEventSubtype.RemoteControlPlay {
stream.play()
} else if event.subtype == UIEventSubtype.RemoteControlPause {
stream.stop()
} else if event.subtype == UIEventSubtype.RemoteControlTogglePlayPause {
toggle()
}
}
}
基本上,当我使用术语"覆盖" (如上所示),我收到错误
"方法不会覆盖其超类中的任何方法。
如果我遗漏了"覆盖",我收到错误:
"方法' remoteControlReceivedWithEvent'使用Objective-C选择器' remoteControlReceivedWithEvent:'与方法冲突" remoteControlReceivedWithEvent"来自超级" UIResponder"使用相同的Objective-C选择器。
我对这一切都很陌生,所以我真的不明白这个问题是什么。有人可以解释一下如何解决这个问题吗?如果您需要更多代码或其他内容,请与我们联系。
我需要使用更多代码进行设置吗?
答案 0 :(得分:6)
UIResponder方法签名与您的功能实现不匹配。 UIResponder具有以下可选事件:
func remoteControlReceibedWithEvent(_ event: UIEvent?)
所以它不能覆盖,因为没有带有非可选参数的函数,但如果删除覆盖它将与ObjC实现冲突,因为选择器名称是相同的。