2

I have two view controllers each one contains UISearchController and a UITableView. The Code in viewDidLoad is:

SearchResultsTableViewController *searchResultController = [[SearchResultsTableViewController alloc]initWithNibName:@"SearchResultsTableViewController" bundle:nil];
UINavigationController *navSearchResultsController = [[UINavigationController alloc] initWithRootViewController:searchResultController];

self.searchController = [[UISearchController alloc] initWithSearchResultsController:navSearchResultsController];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = YES;
[self.searchController.searchBar sizeToFit];
self.searchController.searchBar.delegate = self;
self.searchController.delegate = self;

self.tableView.tableHeaderView = self.searchController.searchBar;
self.tableView.userInteractionEnabled = YES;

The first view controller is the rootViewController, which works perfectly without any problem. The second view controller is being pushed via the navigation controller based on segment selection.

[self.navigationController pushViewController:self.vc];

There is only one problem with the second view controller. When I tap on the searchBar, it animates to the top and goes underneath the navigation bar while the first one animates in its spot and does not go up.

Can anyone tell me how to disable this animation? I want to keep the searchBar in its same place while searching. It's exactly the same implementation for both view controllers. Why does each one act differently?

Thanks,

Mike S
  • 11,329
  • 6
  • 41
  • 76
Missa
  • 145
  • 1
  • 9
  • I don't understand this `the second view controller is being pushed via the navigation controller based on segment selection.` – DeveloBär Dec 14 '15 at 22:18
  • I mean there is a segmented controller. When I tap on the second segment, it navigates to the second viewController. – Missa Dec 15 '15 at 13:29

1 Answers1

0

Set the hidesNavigationBarDuringPresentation boolean on the UISearchController to NO.

self.searchController.hidesNavigationBarDuringPresentation = NO;

Or try this answer, it sounds similar to what you are trying to do. But you would probably want to adjust this line:

[super setActive: visible animated: animated]; // instead of passing animated, pass NO
Community
  • 1
  • 1
Mike S
  • 11,329
  • 6
  • 41
  • 76
  • I tried to set hidesNavigationBarDuringPresentation and it does not work either. And the UISearchController does not have the animated parameter with the setActive method. – Missa Dec 15 '15 at 13:31