Chris
Chris

Reputation: 5627

Can't Call resignFirstResponder from textFieldDidBeginEditing ? (iPhone)

[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.

Upvotes: 3

Views: 2048

Answers (2)

Gregory Holden
Gregory Holden

Reputation: 93

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
 ];

Upvotes: 7

jlehr
jlehr

Reputation: 15617

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.

Upvotes: 7

Related Questions