开发者

becomeFirstResponder not firing

I have a view controller whose viewDidLoad method invokes becomeFirstResponder on a textfield (email) contained within its associated view:

-(void) viewDidLoad {
   [开发者_如何学JAVAemail becomeFirstResponder];
}

This view controller is loaded by pushing it onto the navigation controller's stack. The above code works great for the first time round.

However, later on in the application when I want to return to this view controller the keyboard doesn't appear automatically (this is when using popToViewController:animated). Instead the user has to manually set the focus to a textfield for the keyboard to appear...My guess is viewDidLoad isn't invoked after popToViewController:animated has loaded the relevant view controller?

How do I resolve this issue?


viewDidLoad is only invoked the first time. Use viewWillAppear when you want something to run every time a view appears.


Try putting it in viewWillAppear. viewDidLoad will usually only run once unless you specifically tell it otherwise.

- (void)viewWillAppear:(BOOL)animated {

            [email becomeFirstResponder];

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜