How to auto enable Search bar in UISearchController when that page appear?

时间:2017-12-18 07:06:53

标签: ios swift uisearchcontroller

This is code about my search in the app.

    self.searchController = UISearchController(searchResultsController:  nil)
    self.searchController.searchResultsUpdater = self
    self.searchController.delegate = self
    self.searchController.searchBar.delegate = self
    self.searchController.hidesNavigationBarDuringPresentation = false
    self.searchController.dimsBackgroundDuringPresentation = true
    self.searchController.searchBar.tintColor = UIColor.gray
    self.navigationItem.titleView = searchController.searchBar
    self.definesPresentationContext = true

I want to my search bar auto active when the page appear?

Dose anyone has ideas to do that? You can look on my image to make clear.

enter image description here

1 个答案:

答案 0 :(得分:0)

Try to add to viewWillAppear self.searchController.searchBar.becomeFirstResponder()