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.
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.
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
];
精彩评论