Question

[myTextField becomeFirstResponder];
[myTextField resignFirstResonder];

When I do this -(BOOL)textFieldShouldReturn:(UITextField *)textField , it works. But when I use the same code inside -(void)textFieldDidBeginEditing:(UITextField *)textField , it does not work.

I am certain that it is calling textFieldDidBeginEditing. I have an NSLog inside the method and it is being called.

Was it helpful?

Solution

Before resigning firstResponder status, the textField makes a callback to its own -canResignFirstResponder method, which returns NO if the textField is currently in an edit session. You can implement -textFieldShouldBeginEditing: delegate method to return NO if you want to prevent the editing session from beginning.

OTHER TIPS

This is years back, but needing something identical and this answer being at the top of my search results, I ended up playing and came up with this:

[myTextField performSelector:@selector(resignFirstResponder)
                  withObject:nil
                  afterDelay:0
 ];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top