-1

I have the following code:

 override func viewDidLoad() { super.viewDidLoad() //Looks for single or multiple taps. let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard") view.addGestureRecognizer(tap) // Do any additional setup after loading the view. } func dismissKeyboard() { //Causes the view (or one of its embedded text fields) to resign the first responder status. view.endEditing(true) } 

When running the application This error occurs when the work of error repair another mistake happens

0

4 Answers 4

3

You are getting this error due to the updates to the swift language, change your tap selector for this:

let tap = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard)) 

Make sure that the method dismissKeyboard is in the same view controller, if its not you'll need to do #selector(WhateverHasThatMethod.dismissKeyboard)

Also, make sure that the dismissKeyboard method actually exists, it should be something along the lines of:

func dismissKeyboard(){ YourInputField.endEditing(true) } 
Sign up to request clarification or add additional context in comments.

8 Comments

not working i get breakpoint error !
self Posting.LoginViewController 0x00000001556537c0 tap UITapGestureRecognizer 0x00000001556537c0 UIKit.UIGestureRecognizer UIGestureRecognizer
I have updated my answer to your question with a bit more information, I think you might be missing the method that actually hides your keyboards.
thnx for your help but i get same error !
i have update my question with my function
|
0
 let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard)) 

Comments

0

Since Swift 2.2, use this instead: #selector(YourClass.dismissKeyboard)

Comments

0

Apart from #selector, you can also see some of the new changes in Swift 2.2 from below link:

https://swift.org/blog/swift-2-2-new-features/

will not work in Swift 2.2 but okay in Swift 2.1

override func viewDidLoad() { super.viewDidLoad() navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "addNewFireflyRefernce") } func addNewFireflyReference() { gratuitousReferences.append("We should start dealing in black-market beagles.") } 

will work in Swift 2.2 and higher version

override func viewDidLoad() { super.viewDidLoad() navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: #selector(addNewFireflyRefernce)) } func addNewFireflyReference() { gratuitousReferences.append("Curse your sudden but inevitable betrayal!") } 

Also Swift 3.0 is coming soon:

https://swift.org/blog/swift-3-0-release-process/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.