Keyboard resignfirstresponder when Click Done
-
26-10-2019 - |
Question
I have a textfield called searchBox
and am trying to get rid of the keyboard if the user either clicks on Done.
Is there an IBAction that I need to know to do this?
Solution
You have to make your viewcontroller an UITextFieldDelegate and write in
viewDidLoad:
[searchBox setDelegate:self];
And then write:
- (BOOL)textFieldShouldReturn:(UITextField *)textfield
{
[searchbox resignFirstResponter];
return YES;
}
OTHER TIPS
In your view controller:
- (void)viewDidLoad
{
// ...
searchBox.delegate = self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[searchBox resignFirstResponder];
return YES;
}
See the UITextFieldDelegate documentation for details (you might want to return NO instead of YES in my example).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow