Reputation: 1934
I have a UITextFiled
to which I applied the delegate to close the keyboard by pressing "done".
...
textfield.returnKeyType = UIReturnKeyDone;
textfield.delegate = self;
....
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
How do I invoke a method when I press "done"?
Upvotes: 2
Views: 17137
Reputation: 494
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[add your method here];
return YES;
}
Upvotes: 0
Reputation: 692
Is it that what you want ?
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[add your method here];
return YES;
}
Upvotes: 8
Reputation: 31
#pragma mark -
#pragma mark Text Field Delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if ([textField canResignFirstResponder]) {
[textField resignFirstResponder];
}
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
// add your method here
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
}
Upvotes: 2
Reputation: 69027
When the "done" button is pressed, your editing on the field will end. You can call the delegate method:
textFieldDidEndEditing:
This method is called when the field resigns its first responder status, so it will be called also when you execute your textFieldShouldReturn
like you specified it.
Upvotes: 2