【发布时间】:2021-11-07 07:38:42
【问题描述】:
我有一个 UICollectionView,里面有一个标题视图,导航栏的标题有一个 UISearchController。此代码适用于其他视图,但不适用于此 UICollectionView。我想把这个扔给 SO 社区,看看他们是否可以帮助我解决这个问题。
class ViewBusinessProfile: UICollectionViewController, UICollectionViewDelegateFlowLayout, CLLocationManagerDelegate, UISearchControllerDelegate, UISearchBarDelegate, UISearchResultsUpdating {
@IBOutlet var collectionViews: UICollectionView!
var searchController : UISearchController!
override func viewDidLoad() {
super.viewDidLoad()
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.obscuresBackgroundDuringPresentation = false
self.searchController.searchBar.placeholder = "search products..."
//self.searchController.automaticallyShowsCancelButton = false
self.searchController.definesPresentationContext = true
searchController.searchBar.becomeFirstResponder()
navigationItem.titleView = searchController.searchBar
collectionViews.dataSource = self
collectionViews.delegate = self
}
func updateSearchResults(for searchController: UISearchController) {
}
我可以做些什么来调试或尝试追踪此问题?我在新的 UICollectionView 中重新创建了视图,并且出现了同样的问题。 SearchBar 是可见的,但无法触摸但 Back 按钮在导航栏上有效。
这三个视图都有 UISearchControllers,我在它们之间进行切换。最右边的那个就是发生这个问题的地方。左侧两个视图使用了相同的 UISearchController 代码,效果很好。
【问题讨论】: