In the viewdidload
me开发者_开发技巧thod, I've assigned one of my text fields as first responder by the following way.
[txtUsername becomeFirstResponder];
When the view gets loaded, the text field becomes active and a keyboard appears. But when I tried typing on the keyboard, it is not responding. However when I touched the text field, the keyboard is responding properly. I don't know what is wrong with this. can anyone give me a suggestion?
Thanks in Advance - Abilash
Calling becomeFirstResponder
in viewDidLoad
is not a good idea because the view might not even be on the screen and part of the view hierarchy yet.
Try calling becomeFirstResponder
in viewDidAppear:
instead:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[txtUsername becomeFirstResponder];
}
check if there's any construction of Outlets in your viewDidLoad, may be some of them is called after you set tetUsername as first responder. Also Mike Weller's answer is the most common situation of such problem.
精彩评论