问题
I have a requirement where I have a textfield in a view. When I want to open the view by switching the tab (TabBased Application), first time when the view is loaded the keyboard appears because i loadview method is called. But when I switch to tab2 and again switch to tab1 again, load view is not called. I want the keyboard to appear every time I open the tab1 page.
回答1:
Use -viewWillAppear:
in your view controller to send your text field a -becomeFirstResponder
message, e.g.:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[myTextField becomeFirstResponder];
}
来源:https://stackoverflow.com/questions/2651136/how-to-open-the-view-with-the-keyboard-appearing-when-the-view-is-already-loaded