开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜