当该页出现时,如何在UISearchController中自动启用搜索栏? [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

这是关于我在应用中搜索的代码。

    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

ios swift uisearchcontroller
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.