ios - UISearchContainerViewController 是否在 iOS 上工作

标签 ios uisearchcontroller

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/

相关文章:

ios - 如何在特定接口(interface)上接收 UDP 广播数据包?

iOS UISearchController TableView

swift - 使用 SearchController 推送 ViewController,在搜索栏下显示黑色矩形

swift - UISearch Bar 提示与状态栏重叠,同时呈现为 UISearchController

ios - 城市和国家名称自动填充在搜索区域中

arrays - 在 UITableView 的数组中搜索类的属性

iphone - 就速度而言,Sencha Touch + PhoneGap 与 native 应用程序相比表现如何?

iOS 谷歌登录 : Get list of people from Google+ including their names and profile pictures

ios - 检查多个对象是否包含nil指针,并且仅设置非nil

ios - pangestures 交互就像 iOS 中的邮件应用程序