UISearchController methods not being called

I have created a searchBar programatically and added it to the navigation bar tile view. This is my code:

 UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:self];
searchController.dimsBackgroundDuringPresentation = YES;
// Use the current view controller to update the search results.
searchController.searchResultsUpdater = self;
//Setting Style
searchController.searchBar.barStyle = UIBarStyleBlack;
searchController.searchBar.barTintColor = [UIColor colorWithRed:49.0/255.0 green:49.0/255.0 blue:61.0/255.0 alpha:1.0];
searchController.searchBar.backgroundImage = [UIImage imageNamed:@"BG"];
searchController.searchBar.placeholder = @"Search Artists, Songs, Albums etc.";
searchController.searchBar.keyboardAppearance = UIKeyboardAppearanceDark;
self.definesPresentationContext = YES;
self.navigationItem.titleView = searchController.searchBar;
searchController.delegate = self;
searchController.searchBar.delegate = self;

[searchResultsTableView reloadData];


-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
NSLog(@"Halp.jpg");
return YES;
}

This above method along with all other methods aren't being called. My header looks like this:

<UISearchResultsUpdating, UITableViewDelegate, UISearchControllerDelegate, UISearchBarDelegate, UITableViewDataSource>

Answers


The problem is probably related to this line:

searchController.searchBar.delegate = self;

I suspect that the UISearchController sets itself as the UISearchBar's delegate, so setting it yourself messes things up in some way.


Need Your Help