我将第一个VC作为“ homeController”,它具有UISearchBar的实例并实现其委托(UISearchBarDelegate),并且这样做将实例化第二个VC,即“ searchController”并将其委托也存在于UISearchBar的另一个实例上,我需要修复该冗余。我使用homeController UISearchBarDelegate只是因为它可以实例化“ searchController”。
我一次只能使用一个,也不能使用searchBarShouldBeginEditing或searchBarTextDidBeginEditing。我想使用searchBarTextDidBeginEditing的行为,但它会像疯了似的重新加载。或searchBarShouldBeginEditing的第一秒,并知道应用程序在黑屏状态下的位置,因为绝对不是我设置的默认颜色,因为它更改了我想要的第一秒和第二秒的颜色它是黑色的。顺便说一句,该应用程序未使用“ searchController”中的UISearchBar,而是使用了“ homeController”中的UISearchBar。推荐什么?
就在那儿,我得到了两分。
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
handleShowSearchVC()
return false
}
@objc func handleShowSearchVC() {
let modalUserSearchController = UserSearchController(collectionViewLayout: UICollectionViewFlowLayout())
modalUserSearchController.modalPresentationStyle = .overCurrentContext
navigationController?.pushViewController(modalUserSearchController, animated: true)
}
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
handleShowSearchVC()
}