Why doesn't the UISearchBar get focus and the keyboard doesn't appear when the UIViewController is switched to the navigation controller a second time? It seems that not a single element as a whole has focus.
MY USE CASE : I have 2 view controllers: A and B. Transition - A-> B. A, B are popped onto the navigation controller.
- When I show B , the first time the focus is set to the search bar and the keyboard appears. OK
- Then I return to A. And again from A-> B. Now for the second time it is out of focus and the keyboard does not appear . It is not right.
MY CODE : An IBOutlet connection to the search panel was created on the B UIViewController:
@property (weak, nonatomic) IBOutlet UISearchBar *mySearchBar;
Also installed mySearchBar delegate. I focused on the search bar in the B UIViewController in the viewDidAppear method:
-(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [self performSelector:@selector(setCorrectFocus) withObject:NULL afterDelay:0.2]; } -(void) setCorrectFocus { [self.mySearchBar becomeFirstResponder]; }
Transitions between controllers are performed manually in the code as follows:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"myStoryboard" bundle:nil]; AController *a = [storyboard instantiateViewControllerWithIdentifier:@"A"]; [self.navigationController pushViewController:a animated:NO];
zyxel source share