28 December 2012

Hide keyboard on 'return' key programmaticaly

Added a new UITextField in your iOS app. Everything works perfectly apart from the fact that keyboard DOES NOT DISAPPEAR when you hit the 'return' button. What's the simplest solution to this?



In your viewDidLoad you should include this piece of code:
textField.delegate=self;
or

[textField setDelegate:self];

Then the following must be added to your code:

-(BOOL) textFieldShouldReturn:(UITextField *)textField{
      [textField resignFirstResponder];
      return YES;
}

Cheers.

No comments:

Post a Comment