UINavigationBar自定义返回按钮
2015-10-06 21:46
537 查看
1 | [self.navigationController pushViewController:self.bView animated:YES]; |
1 | self.navigationItem.backBarButtonItem.title = @"back"; |
于是网上搜了一下,别人推荐在B视图的viewDidLoad/viewWillAppear里使用:
12 | UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:nil action:nil]; [self.navigationItem setBackBarButtonItem:backItem]; [backItem release]; |
无奈之下,只好研读UINavigationController ClassReference去,在“Updating the Navigation Bar”小节,有这么一段话:
The bar button itemon the left side of the navigation bar allows for navigation backto the previous view controller on the navigation stack. Thenavigation controller updates the left side of the navigation baras
follows:
If the newtop-level view controller has a custom left bar button item, thatitem is displayed. To specify a custom left bar button item, setthe leftBarButtonItem property of the view controller’s navigationitem.
If the top-levelview controller does not have a custom left bar button item,but the navigationitem of the previous viewcontroller
has a valid item in itsbackBarButtonItem property,the navigation bar displays that item.
If a custom barbutton item is not specified by either of the view controllers, adefault back button is used and its title is set to the value ofthe title property of the previous view controller—that is, theview
controller one level down on the stack. (If there is only oneview controller on the navigation stack, no back button isdisplayed.)
我大致解释一下,使用pushViewController切换到下一个视图时,navigationcontroller按照以下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
相关文章推荐
- UINavgationBar之UIBarButtonItem
- 关于将navigationBar的背景设置成透明,并且让navigationItem展示出来
- UINavigationItem UINavigationBar 关系分析
- UINavigationBar
- 修改UINavigationbar背景
- UIToolbar与UINavigationBar笔记
- iOS7 UINavigationBar设置白色但是出现半透明解决方法
- UINavigationBar 一些使用总结
- 自定义多视图
- 【iOS7】定制iOS 7中的导航栏和状态栏
- Objective-C ,ios,iphone开发基础:Category(分类,类别,范畴) ,UINavigationBar设置背景图片适配
- ios7 自定义UINavigationBar UIBarButtonItem 10px的偏移纠正
- iOS之UINavigationBar的使用
- 改变状态栏和导航栏的透明度
- UINavigation category 定制
- ios7适配 通知栏UINavigationBar遮挡view的问题
- IOS开发之UINavigationBar
- UINavigationbar/UINavigationItem/UITabBar/UITabButton/UITabBarItem粑粑粑粑~
- UINavigationBar
- iOS 7自定义导航栏状态栏