iOS 修改导航栏的返回按钮的内容
2014-11-08 16:50
465 查看
http://zgia.net/?p=306
A视图进入B视图,如下,self指的A,bView指的B。
一开始想当然的,在B视图的viewDidLoad里直接使用:
来更改后退按钮标题,结果后退后,发现A视图的导航栏标题也变成“back”了。
于是网上搜了一下,别人推荐在B视图的viewDidLoad/viewWillAppear里使用:
我试了,发现无效。
无奈之下,只好研读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 its backBarButtonItem 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了。
A视图进入B视图,如下,self指的A,bView指的B。
1 | [self.navigationController pushViewController:self.bView animated:YES]; |
1 | self.navigationItem.backBarButtonItem.title = @"back"; |
于是网上搜了一下,别人推荐在B视图的viewDidLoad/viewWillAppear里使用:
123 | UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:nil action:nil];[self.navigationItem setBackBarButtonItem:backItem];[backItem release]; |
无奈之下,只好研读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 its backBarButtonItem 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了。
1 2 3 4 | UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:nil action:nil]; [self.navigationItem setBackBarButtonItem:backItem]; [backItem release]; [self.navigationController pushViewController:self.bView animated:YES]; |
相关文章推荐
- iOS修改导航栏的返回按钮的内容
- iOS 修改导航栏的返回按钮的内容
- iOS 修改导航栏的返回按钮的内容
- iOS修改导航栏的返回按钮的内容
- ios中怎么修改导航栏返回按钮
- IOS 怎么修改Navigation Bar上的返回按钮文本颜色,箭头颜色以及导航栏按钮的颜色
- iOS导航栏 修改系统返回按钮
- iOS修改导航栏返回按钮样式
- iOS修改导航返回按钮内容和返回指定页
- IOS修改Navigation Bar上的返回按钮文本颜色,箭头颜色以及导航栏按钮的颜色
- IOS 怎么修改Navigation Bar上的返回按钮文本颜色,箭头颜色以及导航栏按钮的颜色
- 「iOS」怎么修改去掉Navigation Bar上的返回按钮文本颜色,箭头颜色以及导航栏按钮的颜色
- 设置状态栏、导航栏背景颜色,修改导航栏返回按钮颜色
- 自定义iOS导航栏背景,标题和返回按钮文字颜色
- navigationBar 导航栏背景颜色、返回按钮修改
- iOS 设置导航栏返回按钮中箭头的颜色
- ios设置导航栏背景图片、返回按钮背景、标题颜色等等
- IOS 改变导航栏返回按钮的标题
- iOS 设置导航栏返回按钮中箭头的颜色
- 修改IOS中UISearchBar的取消按钮背景、搜索内容输入文本框背景和UISearchBar的背景