Question

I have a UISearchDisplayController that works perfectly in one of my iOS6 app. Now, I want to migrate this app to iOS7.

I had read the Apple docs, and it says the following :

Starting in iOS 7.0, you can use a search display 
controller with a navigation bar (an instance of 
the UINavigationBar class) by configuring the 
search display controller’s displaysSearchBarInNavigationBar 
and navigationItem properties.

displaysSearchBarInNavigationBar is pretty easy to set up. But the only clue I have for navigationItem is the following :

Important: The system raises an exception if you 
attempt to set the titleView property for a search 
display controller’s navigation item.

I can't seem to find example of how to set the navigationItem. How to I say to my navigationBar to embed my searchBar? Somebody can show me an example?

Thank you in advance!

Was it helpful?

Solution

UISearchDisplayController creates and manages the navigation item needed to display the search bar in the navigation bar. You don't need to create your own, although you can access it via searchDisplayController.navigationItem after displaysSearchBarInNavigationBar has been set to YES (the navigationItem is created lazily)

When the view controller with the search display controller is asked for its navigationItem, the search display controller will return its item (which contains the search bar) instead of the view controller's.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top