Reputation: 133
I have a problem and I can't find the solution for it. At the moment I have a tap gesture recogniser in my VC's viewDidLoad() that will dismiss the keyboard if a tap is recorder on screen. Problem is that when the user has finished completing the text fields and he presses the "Register Account" button it is still recognised as a tap and only removes the keyboard but the button does not respond to the tap and the selector function is not called. I want as soon as the button was tapped with the keyboard on screen to call the function and do its business. Please help. Just posting the first line of the function called by the button because for this question is as far as I have got:
@objc fileprivate func createAccount() {
confirmPasswordTextField.resignFirstResponder()
Upvotes: 0
Views: 441
Reputation: 13459
If you just want to make all buttons actionable (along with the keyboard dismissing) all you have to do is make your tap gesture recognizer not cancel touches in view:
var cancelsTouchesInView: Bool { get set }
So just set:
myTapGesture.cancelsTouchesInView = false
https://developer.apple.com/documentation/uikit/uigesturerecognizer/1624218-cancelstouchesinview
This will make it so that when the user taps on the "Register Account" button the keyboard will dismiss and the action will also be performed.
Upvotes: 1