本文主要是介绍修改返回按钮 标题 (UINavigationBar),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
UINavigationController Class Reference,在“Updating the Navigation Bar”小节,有这么一段话:
The bar button item on the left side of the navigation bar allows for navigation back to the previous view controller on the navigation stack. The navigation controller updates the left side of the navigation bar as follows:
- If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the leftBarButtonItem property of the view controller’s navigation item.
- If the top-level view controller does not have a custom left bar button item, but the navigation item of the previous view controller has a valid item in itsbackBarButtonItem property, the navigation bar displays that item.
- If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)
我大致解释一下,使用pushViewController切换到下一个视图时,navigation controller按照以下3条顺序更改导航栏的左侧按钮。
1、如果B视图有一个自定义的左侧按钮(leftBarButtonItem),则会显示这个自定义按钮;
2、如果B没有自定义按钮,但是A视图的backBarButtonItem属性有自定义项,则显示这个自定义项;
3、如果前2条都没有,则默认显示一个后退按钮,后退按钮的标题是A视图的标题。
按照这个解释,我把UIBarButtonItem *backItem……这段代码放在A视图的pushViewController语句之前。
OK问题解决了,B视图的后退按钮的标题变成back了。
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:nilaction:nil];
[self.navigationItem setBackBarButtonItem:backItem];
[backItem release];
[self.navigationController pushViewController:self.bView animated:YES];
转载自:http://zgia.net/?p=306
这篇关于修改返回按钮 标题 (UINavigationBar)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!