Nov 162009

Here is a handy tip that I came across. If you need to close the keyboard after a user enters the details in the text field all you have to do is addto your .h file and add this code to your .m file.

Add this to your .h file:

@interface WhatEverViewController : UIViewController {
IBOutlet UITextField * firstTextField;
IBOutlet UITextField * secondTextField;
IBOutlet UITextField * doneButtonPressed;
}

@property (nonatomic, retain) IBOutlet UITextField * firstTextField;
@property (nonatomic, retain) IBOutlet UITextField * secondTextField;
@property (nonatomic, retain) IBOutlet UITextField * doneButtonPressed;

@end

Add this to your .m file:

@synthesize firstTextField, secondTextField, doneButtonPressed;

- (BOOL)textFieldShouldReturn:(UITextField *)doneButtonPressed {
NSLog(@”Keyboard Done Pressed”);

[doneButtonPressed resignFirstResponder];

return YES;
}

Thanks to megatron.

Sorry, the comment form is closed at this time.