Skip to content

Instantly share code, notes, and snippets.

@pkuecuekyan
Last active March 23, 2021 14:54
Show Gist options
  • Save pkuecuekyan/23c72d60e9ccd921cf05 to your computer and use it in GitHub Desktop.
Save pkuecuekyan/23c72d60e9ccd921cf05 to your computer and use it in GitHub Desktop.
Set up a UISearchContainerViewController inside a UITabBar for tvOS 9
func setupTabBarWithSearchContainerView() {
// configure a UIViewController to display search results
// needs to conform to the UISearchResultsUpdating protocol
let searchResultsViewController = SearchResultsViewController()
// setup UISearchController and hook up to search results UIViewController
let searchController = UISearchController(searchResultsController: searchResultsViewController)
searchController.searchResultsUpdater = searchResultsViewController
searchController.hidesNavigationBarDuringPresentation = false
// create a search container that will hold the UISearchController
let searchContainerViewController = UISearchContainerViewController(searchController: searchController)
searchContainerViewController.tabBarItem = UITabBarItem(title: "Search", image: UIImage(named: "searchIcon"), tag: 0)
// set up a nav bar to hold the UISearchContainerViewController
let searchNav = UINavigationController(rootViewController: searchContainerViewController)
// create the tabBar and hold onto the search container
let tabs = UITabBarController()
tabs.viewControllers = [searchNav]
self.window!.rootViewController = tabs;
self.window?.makeKeyAndVisible();
}
/* .-----------------------------------.
* | UISearchContainerViewController |
* | .-------------------------------. |
* | | SearchController | |
* | | .---------------------------. | |
* | | | ResultsViewController | | |
* | | '---------------------------' | |
* | '-------------------------------' |
* '-----------------------------------'
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment