UISearchController search bar doesn't get focus

前端 未结 2 1439
忘了有多久
忘了有多久 2021-01-21 08:53

In my project, If a controller (containing UISearchController) is pushed second time on to the navigation stack, Search bar can\'t seem to get focus. The following GIF recoding

相关标签:
2条回答
  • 2021-01-21 09:25

    Try this

    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        self.definesPresentationContext = YES;
     }
    
    - (void)viewDidDisappear:(BOOL)animated {
        self.definesPresentationContext = NO;
        [super viewDidDisappear:animated];
     }
    

    it working fine for me, but not sure is it good solution or not?

    0 讨论(0)
  • 2021-01-21 09:32

    You need to set your UISearchControllerDelegate

        class SearchController: UITableViewController, UISearchControllerDelegate, UISearchBarDelegate {
        override func viewDidLoad() {
            super.viewDidLoad()
    
            searchController = UISearchController(searchResultsController: nil)
            searchController.delegate = self
            searchController.searchBar.delegate = self
    
            self.definesPresentationContext = false
        }
    

    in the storyboard also need to change the segue from Show Push, to Show Replace

    or use extensions however the cool kids are doing it now.

    0 讨论(0)
提交回复
热议问题