Reputation: 2669
Using what I've read online people say put a button in the background of the app then when clicked that button handles closing the keyboard. However reading some other people they say resign first repsonder for the text field - does that mean the textfield has taken control of the keyboard and wont release it until specifically told to?
My .h has:
@interface SearchItems : UIViewController {
IBOutlet UIButton *btnKeyboard;
IBOutlet UITextField *txtWhat;
IBOutlet UITextField *txtWhere;
}
@property (nonatomic, retain) IBOutlet UIButton *btnKeyboard;
@property (nonatomic, retain) IBOutlet UITextField *txtWhat;
@property (nonatomic, retain) IBOutlet UITextField *txtWhere;
-(IBAction)closeKeyboard;
@end
The .m (cut down)
@synthesize btnKeyboard, txtWhat, txtWhere;
-(IBAction)closeKeyboard {
[txtWhere resignFirstResponder];
[txtWhat resignFirstResponder];
}
Which isn't working, any ideas?
Thanks
Tom
Upvotes: 0
Views: 629
Reputation: 2499
Try using the delegate methods to resignResponder:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
Apart from this one you can also use this delegate method:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
}
These two methods mainly should be able to solve your keyboard hiding problem rather than using the background button technique.
Upvotes: 1