0

I am trying to implement search in tvOS and somehow achieved to show controller in tvOS. The issue is that I know how to present the UISearchController but I want to show it on the same home screen. I am using a tab bar and I have a multiple menu, which also has search option.

UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

[self presentViewController:searchController animated:YES completion:nil];

This how I am currently presenting, rather then present it as a new controller I want to show it on the same screen. I tried in many ways but nothing gives me exactly what I want. If any one has idea please provide some suggestion! Thanks in advance.

jcaron
  • 17,302
  • 6
  • 32
  • 46
Yohan
  • 1,108
  • 9
  • 21

2 Answers2

2

You Can try this Code

UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController: <your results controller>];  
UISearchContainerViewController *containerVC = [[UISearchContainerViewController alloc] initWithSearchController: searchController];  
containerVC.title = @"Search";
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: containerVC];  
UITabBarController *tbc = [UITabBarController new];  
tbc.viewControllers = @[nav];  
window.rootViewController = tbc;  
[window makeKeyAndVisible]; 

from this Original link

Community
  • 1
  • 1
Vipulk617
  • 799
  • 1
  • 7
  • 23
  • This is creating separate one with search tab!! It is not exactly i want. It should be like tab youtube app is the example. – Yohan Dec 30 '15 at 06:14
0
    let searchController = UISearchController(searchResultsController: UIViewController())

           searchController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
           searchController.view.frame = searchView.bounds

           let searchContainer: UISearchContainerViewController = UISearchContainerViewController(searchController: searchController)
    
    searchController.delegate = self
    searchController.searchResultsUpdater = self
    searchController.searchBar.tintColor = .red
    searchController.view.backgroundColor = UIColor(red: 0.25, green: 0.25, blue: 0.25, alpha: 1.0)
        searchController.searchBar.backgroundColor = UIColor(red: 0.25, green: 0.25, blue: 0.25, alpha: 1.0)

           let searchNavigationController = UINavigationController(rootViewController: searchContainer)
           searchNavigationController.navigationBar.isTranslucent = true
           searchNavigationController.navigationBar.tintColor = .white
           searchNavigationController.tabBarItem.title = "Search"

    searchView.addSubview(searchNavigationController.view)
           searchNavigationController.didMove(toParent: self)