gpt4 book ai didi

ios - 无法在 UISearchController 上成为 FirstResponder 工作

转载 作者:行者123 更新时间:2023-11-30 11:14:09 27 4
gpt4 key购买 nike

viewDidLoad()中:

searchController = UISearchController(searchResultsController: nil)
let cancelButtonAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(cancelButtonAttributes, for: .normal)

searchController?.dimsBackgroundDuringPresentation = false
searchController?.searchResultsUpdater = self
searchController?.delegate = self
searchController?.searchBar.tintColor = UIColor.black
searchController?.searchBar.barTintColor = UIColor(white: 0.9, alpha: 0.9)
searchController?.searchBar.placeholder = NSLocalizedString("Search", comment: "")
searchController?.hidesNavigationBarDuringPresentation = false
self.navigationItem.titleView = self.searchController?.searchBar

searchController?.isActive = true
self.searchController?.becomeFirstResponder()
self.searchController?.searchBar.becomeFirstResponder()

这是委托(delegate)方法:

extension SearchMembers :  UISearchControllerDelegate {
func didPresentSearchController(searchController: UISearchController){
self.searchController?.searchBar.becomeFirstResponder()
}
}

在我的测试中,didPresentSearchController(searchController:) 从未被调用。

我不知道为什么,但无论我做什么都不起作用。

有什么想法吗?

编辑唯一有效的解决方案

      delay(0.6) {
self.searchController?.searchBar.becomeFirstResponder()
}

这会产生不必要的延迟

最佳答案

根据documentation didPresentSearchController:

This method is only called when the search controller is automatically presented. It is not called if you explicitly present the search controller.

如果您想显式显示搜索结果界面,请将搜索 Controller 包装在 UISearchContainerViewController 对象中并显示该对象。

关于ios - 无法在 UISearchController 上成为 FirstResponder 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51904153/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com