Reputation: 7
I am using Xcode 7.1 and iOS 9.1 beta. I imported my working code from Xcode 6.2 and I am getting an error message that "Method does not override any method from its superclass"
Its not a latest swift syntax issue. I already rule out following conditions:
- syntax is updated for swift 2.0:
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?)
- On rewrite in Xcode, syntax is suggested by xcode itself.
- Most important, I don't see this issue if I create a new test project and try to override touchesBegan. Problem is only with the imported code.
- I am overriding this method in UIViewController subclass.
- Same issue is also reproducible in Xcode 7 beta 6
It looks to me that either its a beta bug with imported code or something wrong with my configuration. Any suggestion are welcome. Thanks for the Help.
Upvotes: 0
Views: 4448
Reputation: 71
One thing to look for is whether or not you have added a gesture to the view either programmatically or to a view within that storyboard ViewController. If that gesture has "Cancels touches in view" selected in the storyboard or if you set that to true programmatically it can prevent any of the "touches" overrides from being called.
Upvotes: 0
Reputation: 171
If you imported the code, it may still be trying to link to another project. If you paste your code into TextEdit and then recopy it, that will break any links that your code may have.
You could also try updating Xcode to the latest version.
Try that and let me know how it goes.
Upvotes: 1
Reputation: 2198
These methods seem not to be called within the UIViewController class anymore while they still are within its subviews. While I haven't figured out how to reach out to those from my UIViewController directly there are several approaches to get what you need.
You can either make your view a custom class and receive/handle the touches received within your own UIView class or - if you need touchesBegan for a thing like dismissing the keyboard correctly when tapped anywhere - just add a UITapGestureRecognizer
within your UIViewController and add it to its view below all other potential subviews like textFields or buttons: view.insertSubview(gestureRecognizer, atIndex: 0)
. Alternatively use Storyboard to drag a TapGestureRecognizer to the desired view and connect it as an action @IBAction func viewTapped(sender: AnyObject)
to your storyboard.
Hope it helps...
Upvotes: 0
Reputation: 1740
This is the one that automatically appears to me when I create the function. Try this one. I just updated to xCode 7 just now and this works for me. Next time you get an error from a function that Swift automatically finishes for you, try it. I removed my touchesBegan function and then just started rewriting touchesBegan and this is what it autocompleted it to.
override func touchesBegan(touches: Set<UITouch>?, withEvent event: UIEvent?) {
//Code
}
Upvotes: 0
Reputation: 7
Well, We moved our code from Xcode 6.2 to Xcode 7. In my project we had a SET class somewhere. So, After migration, I was not able to figure out why I was still getting overriding issue even I have right swift 2.0 syntax.
I got an clue from its color. swift Set has purple color and Mine custom Set has light blue color.
Anyway,I don't think, this is a common issue. But still I want to post my answer
Upvotes: 0