这个问题在这里已有答案:
这是关于我在应用中搜索的代码。
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
当页面出现时,我希望我的搜索栏自动激活?
有没有人有想法这样做?您可以查看我的图像以明确说明。
尝试添加到viewWillAppear self.searchController.searchBar.becomeFirstResponder()