【发布时间】:2016-01-28 05:08:27
【问题描述】:
当我这样声明它们时,我对这两个函数的行为非常奇怪:
override func touchesBegin(touches: NSSet, withEvent event: UIEvent)
override func touchesMoved(touches: NSSet, withEvent event: UIEvent)
我收到错误消息:
Method does not override any method from its superclass
但是当我这样声明它们时:
func touchesBegin(touches: NSSet, withEvent event: UIEvent)
func touchesMoved(touches: NSSet, withEvent event: UIEvent)
我收到错误消息:
Method 'touchesBegan(_:withEvent:)' with Objective-C selector 'touchesBegan:withEvent:' conflicts with method 'touchesBegan(_:withEvent:)' from superclass 'UIResponder' with the same Objective-C selector
Method 'touchesMoved(_:withEvent:)' with Objective-C selector 'touchesMoved:withEvent:' conflicts with method 'touchesMoved(_:withEvent:)' from superclass 'UIResponder' with the same Objective-C selector
那么我是否应该覆盖超类中的函数?
【问题讨论】:
-
您能否扩展代码的
...部分。 -
对不起,我的意思是填写签名,例如 touchesBegan(...
-
试试
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
标签: ios swift overriding superclass touchesbegan