UISearchContainerViewController 存在于 tvOS 和 iOS 上。
Apple 有展示如何在 tvOS 中使用它的示例代码:他们配置了一个 UISearchController,将其交给 UISearchContainerViewController,将其包装在 UINavigationController 中,并使其成为 UITabBarController 的子级之一。
但我从未在 iOS 上看到 UISearchContainerViewController 的例子,我无法让它在那里工作。例如,除了我将 UISearchContainerViewController 推送到导航堆栈上,或者我将它包装在导航 Controller 中并呈现它,或者其他任何方式之外,我完全按照 Apple 的方式进行操作;而且没有搜索字段,所以整个东西都没用。
有没有人让 UISearchContainerViewController 在 iOS 上做任何有用的事情?
最佳答案
我正在寻找同一个问题的答案。但我是这样工作的:
基础风投
let vc = SearchContainerVC()
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true, completion: nil)
SearchContainerVC
class SearchContainerVC: UISearchContainerViewController {
init() {
let searchResultsTableVC = SearchResultsTableViewController()
let searchVC = UISearchController(searchResultsController: searchResultsTableVC)
searchVC.searchBar.searchBarStyle = .minimal
searchVC.searchBar.showsCancelButton = true
searchVC.searchBar.delegate = searchResultsTableVC
searchVC.searchResultsUpdater = searchResultsTableVC
let searchBar = searchVC.searchBar
searchBar.delegate = searchResultsTableVC
searchBar.sizeToFit()
searchBar.placeholder = "Search for something"
searchVC.hidesNavigationBarDuringPresentation = false
searchVC.dimsBackgroundDuringPresentation = true
super.init(searchController: searchVC)
navigationItem.titleView = searchBar
}
}
SearchResultsTableViewController
class SearchResultsTableViewController: UITableViewController {
// I use a Table to show search items
}
关于ios - UISearchContainerViewController 是否在 iOS 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46076777/