I am trying to make the keyboard disappear when a UIButton is pressed –
-(IBAction)nextButtonPressed{
[usernameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
}
I have declared the button as IBOutlet and connected it to the IBAction in the storyboard. But the code however does not work and keyboard remains visible. What am I doing wrong ?
First you need to subscribe to the UITextFieldDelegate Protocol in your View/ViewController’s header file like this:
Make sure you’re setting your view/viewcontroller to be the UITextField’s delegate after you init the textfield in the .m:
And you can do this :
Hope it’ll help