Can't change back button title from "Search" in pushed vc's navbar when a searchbar is displayed in previous view's navbar

StackOverflow https://stackoverflow.com/questions/19942730

Question

I can't change the back button title on a pushed view when the previous view has a search bar displayed in the navigation controller.

ListView has a UISearchBar, displaying in navigation bar.

DetailView is pushed from ListView's contained table. The button in the navbar in Detail view is always titled "Search", unless the search bar is removed from the navbar.

I've tried changing the back button text on DetailView's navitem in storyboard without effect. Changing the main title in this navitem does work. Removing the title reverts the name back to the view controller's name - so this is the live navitem.

I've tried setting self.navigationitem.backBarButtonItem.text = @"ASDF" in viewDidLoad, and still the back button title remains Search.

UISearchDisplayController does not respond to UIViewController's setTitle method - I tried casting my instance to a regular view controller to set the title.

It looks like the back button title is being set to the searchDisplayController's hard-coded, immutable title "Search". Is this really intended behavior? What am I doing wrong?

Was it helpful?

Solution

I figured out the answer from the UISearchDisplayController documentation - when displayed in a navbar, the navbar uses the Search controller's navigation item instead of it's own. The default title for that item is Search.

Setting self.searchDisplayController.navigationItem.title = @"MY TITLE" worked.

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