Reputation: 471
I have a view controller whose viewDidLoad method invokes becomeFirstResponder on a textfield (email) contained within its associated view:
-(void) viewDidLoad {
[email 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?
Upvotes: 4
Views: 855
Reputation: 1430
viewDidLoad
is only invoked the first time. Use viewWillAppear
when you want something to run every time a view appears.
Upvotes: 4
Reputation: 5940
Try putting it in viewWillAppear. viewDidLoad will usually only run once unless you specifically tell it otherwise.
- (void)viewWillAppear:(BOOL)animated {
[email becomeFirstResponder];
}
Upvotes: 3