如何在页面出现时自动启用UISearchController中的搜索栏?

问题描述:

这是我在应用程序中搜索的代码。如何在页面出现时自动启用UISearchController中的搜索栏?

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 

我想让我的搜索栏在页面出现时自动激活吗?

剂量任何人有想法做到这一点?你可以看看我的形象来说明。

enter image description here

尝试添加到viewWillAppear中self.searchController.searchBar.becomeFirstResponder()

+0

感谢您的回答 –