How do you reference a UISearchController using storyboards

I added a search bar and a search controller (assuming I'm adding to the storyboard, since they don't have a SearchController object to drag and drop).

My problem is how to set properties on this SearchController now? self.searchController does not work, and Xcode says it is automatically added when I add a UISearchBar to the view. What am I doing wrong? The reason I need access is because I can set up a search results table, for example:

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 an example here: https://github.com/dempseyatgithub/Sample-UISearchController

Which says it uses storyboards, doesn't actually use storyboards to add to the UISearchController, but uses code to isolate and initialize and set the frame.

+5
source share
2 answers

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

-5
source

Important: UISearchDisplayController is deprecated in iOS 8. (Note that UISearchDisplayDelegate is also deprecated.) Use the UISearchController instead to control the presentation of the search bar and display search results in iOS 8 and later.

As mentioned in the White Paper, it would be better to stop adding the old UISearchDisplayController style to apps targeting iOS 8.0+. But it seems that they did not delete the old one from the UI Controller library in Xcode6.1. They also did not add a new UISearchController. Wait for the next patch.

But you can still add a new one by code:

  _searchController=[[UISearchController alloc] initWithSearchResultsController:self]; 
+19
source

Source: https://habr.com/ru/post/1205804/


All Articles