开发者

becomeFirstResponder not firing

开发者 https://www.devze.com 2023-03-30 10:37 出处:网络
I have a view controller whose viewDidLoad method invokes becomeFirstResponder on a textfield (email) contained within its associated view:

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

精彩评论

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

关注公众号