How to show keyboard without touching the UISearch

2019-02-16 15:35发布

问题:

Can I show the keyboard for UISearchbar on viewWillAppear method call without touching the UISearchbar ?

回答1:

[mySearchBar becomeFirstResponder];


回答2:

Working Solution:-

Don't use [self.searchController setActive:YES] before becomeFirstResponder.

- (void)viewDidAppear:(BOOL)animated {
         [super viewDidAppear:animated];
         dispatch_async(dispatch_get_global_queue(0, 0), ^{
         dispatch_async(dispatch_get_main_queue(), ^{
       //[self.searchController setActive:YES];
         [self.searchController.searchBar becomeFirstResponder];
       });
   });
}