5
votes

I've added a Search Bar & Search Display Controller (assuming that's what I add in storyboard since theirs no 'SearchController' object to drag out).

My issue is how do I set properties on that SearchController now? self.searchController doesn't work and Xcode says it's automatically added when I add the UISearchBar to the view. What am I doing wrong? The reason I need access it is so I can set the results search table, like so:

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

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

self.searchController.searchResultsUpdater = self;

I noticed the example here: https://github.com/dempseyatgithub/Sample-UISearchController

Which says it uses storyboards, doesn't actually use storyboards for adding in the UISearchController, but uses code by allocating and initializing and setting the frame.

2
Thanks boss, if you want to put this as the answer I'll gladly accept.James

2 Answers

19
votes

Important: UISearchDisplayController is deprecated in iOS 8. (Note that UISearchDisplayDelegate is also deprecated.) To manage the presentation of a search bar and display search results in iOS 8 and later, instead use UISearchController.

As mentioned in Official doc, it'd be better to stop adding the old style UISearchDisplayController to apps targeting iOS 8.0+. But it seems that they haven't removed the old one from the UI Controller library in Xcode6.1. They haven't added the new UISearchController neither. Let's wait for next patch.

But you can still add the new one by code:

  _searchController=[[UISearchController alloc] initWithSearchResultsController:self];
-5
votes

When you drag the search bar and search Display controller object out onto your table view, an IBOutlet called searchDisplayController is automatically added to your controller, not one called searchController. It also sets the data source and delegate for you.