searchResultsUpdater
에 대해 어떻게 다른 ViewController
을 설정할 수 있습니까? 이런 식으로 시도했지만 결과가 업데이트되지 않습니다.검색 결과를위한 ViewControllerUpdater
let searchNav = storyboard!.instantiateViewController(withIdentifier: "SearchControllerNav") as! UINavigationController
let vc = searchNav.topViewController as! PageMenuVC
let searchVC = storyboard!.instantiateViewController(withIdentifier: "SearchVC") as! SearchVC
self.searchController = UISearchController(searchResultsController: vc)
vc.searchController.searchResultsUpdater = searchVC
여기 내 PageMenuVC : 당신이 더 많은 정보가 필요하면
//MARK: Filter
func filterContentForSearchText(searchText: String, scope: String = "All") {
filteredUsers = allUsers.filter { user in
return user.name.lowercased().contains(searchText.lowercased())
}
collectionView.reloadData()
}
//MARK: SearchResultDelegate
func updateSearchResults(for searchController: UISearchController) {
let searchBarText = searchController.searchBar.text!
filterContentForSearchText(searchText: searchBarText)
self.searchController = searchController
collectionView.reloadData()
}
알려 : SearchVC
에서
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
var controllerArray : [UIViewController] = []
let searchVC = storyboard?.instantiateViewController(withIdentifier: "SearchVC")
controllerArray.append(searchVC!)
let testVC = storyboard?.instantiateViewController(withIdentifier: "test")
controllerArray.append(testVC!)
// Customize menu (Optional)
let parameters: [CAPSPageMenuOption] = [
.scrollMenuBackgroundColor(UIColor(red: 30.0/255.0, green: 30.0/255.0, blue: 30.0/255.0, alpha: 1.0)),
.viewBackgroundColor(UIColor(red: 20.0/255.0, green: 20.0/255.0, blue: 20.0/255.0, alpha: 1.0)),
.selectionIndicatorColor(UIColor.orange),
.bottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)),
.menuItemFont(UIFont(name: "HelveticaNeue", size: 13.0)!),
.menuHeight(40.0),
.menuItemWidth(90.0),
.centerMenuItems(true)
]
// Initialize scroll menu
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height), pageMenuOptions: nil)
self.addChildViewController(pageMenu!)
self.view.addSubview(pageMenu!.view)
pageMenu!.didMove(toParentViewController: self)
}
나는이 기능을 가지고!
희망이 있습니다. https://developer.apple.com/library/content/samplecode/TableSearch_UISearchController/Introduction/Intro.html – Mannopson