Last active
March 23, 2021 14:54
-
-
Save pkuecuekyan/23c72d60e9ccd921cf05 to your computer and use it in GitHub Desktop.
Set up a UISearchContainerViewController inside a UITabBar for tvOS 9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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