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

문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top