Automatic Popovers

In a few situations, the framework will automatically create and display a popover for you. One such situation is what happens when a search bar (a UISearchBar) tied to a search display controller (UISearchDisplayController) appears in a toolbar (UIToolbar) on the iPad. Recall the search display controller example from Chapter 21, where we search a list of the 50 United States; I’ll modify that example to demonstrate. In the nib editor, start with a toolbar at the top of the root view, and drag into it the combined Search Bar and Search Display Controller object from the Object library. This causes a whole bunch of outlets to be configured automatically:

  • The search bar’s delegate is the File’s Owner.
  • The File’s Owner’s searchDisplayController is the search display controller. This is a UIViewController property that I didn’t mention in Chapter 21, because its worth is not clear when a UISearchDisplayController is created and configured in code. When a UISearchDisplayController is instantiated from a nib, however, this property is an outlet that retains the search display controller, as well as providing access to it in code.
  • The search display controller’s search bar is the search bar.
  • The search display controller’s delegate, searchContentsController, searchResultsDataSource, and searchResultsDelegate are the File’s Owner. Of these, only the latter two appear to be of importance in this example.

Now for the code. When our view controller loads its view, we ...

Get Programming iOS 6, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.