Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nothing happens when I click UISearchBar in NavigationBar

I added a UISearchBar to my initial UIViewController and everything works fine. However when I go to add the same UISearchBar, the same way to another ViewController that's pushed ontop of the first one, nothing seems to happen when I click into the searchBar. No delegate method is fired, no keyboard comes up, nothing.

This is how I'm adding it to the navigationBar:

- (void)viewDidLoad {
    [super viewDidLoad];


    UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    searchResultsController.tableView.dataSource = self;
    searchResultsController.tableView.delegate = self;

    self.searchResults = [NSMutableArray array];

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
    self.searchController.searchResultsUpdater = self;
    self.searchController.hidesNavigationBarDuringPresentation = NO;



    self.searchController.searchBar.placeholder = NSLocalizedString(@"Search, eh?", nil);

    // Include the search bar within the navigation bar.
    self.navigationItem.titleView = self.searchController.searchBar;

    self.definesPresentationContext = YES;


}

Like I said it works in the first UIViewController, am I missing something in the other 2-3 viewControllers I've tried adding this too? I don't see why the searchBar shows up in the navBar but nothing is happening upon clicking into it. I've also set the delegate like so:

@interface ViewController () <UISearchResultsUpdating>
like image 783
Kimberly Avatar asked Dec 21 '14 21:12

Kimberly


1 Answers

Try setting definesPresentationContext to NO on the first view controller as soon as you present a new one on.

I believe that the presentation walks up the view controller hierarchy looking for the first one that defines a context and not down.

like image 80
Cezar Avatar answered Nov 14 '22 22:11

Cezar