0

Pressing the dismiss keyboard button (in the lower right of the keyboard) is not calling method:

- (BOOL)textFieldShouldReturn:(UITextField *)textField

How can I handle this event and how do I differentiate it from other events (if it's handled by an aggregate event handler)?

petert
  • 6,672
  • 3
  • 38
  • 46
Jim
  • 5,940
  • 9
  • 44
  • 91

2 Answers2

0

You can listen for keyboard hide UIKeyboardWillHideNotification notification.

Example code is here http://developer.apple.com/iphone/library/samplecode/KeyboardAccessory/Listings/Classes_ViewController_m.html

Or even you can implement method

-(void)textFieldDidEndEditing:(UITextField *)textField
iShwar
  • 1,625
  • 1
  • 16
  • 31
0

Are you setting the delegate for the textfield? Fix in Interface Builder, or in code; e.g.:

self.TEXTFIELDNAME.delegate = self;

See this post too, should help.

Community
  • 1
  • 1
petert
  • 6,672
  • 3
  • 38
  • 46
  • I set the delegate in IB. It works fine with the return key, calling textfieldshouldreturn and performing like I expect it to in that case. It's not capturing the dismiss keyboard event though. Is textfieldshouldreturn supposed to handle that key? Also, how would setting the delegate programmatically change the behavior? – Jim Jul 06 '11 at 16:48
  • When I hit the dismiss keyboard key, the textFieldDidEndEditing: method is called. If I could determine what key was pressed to get here, that would help. – Jim Jul 07 '11 at 01:23