UINavigationBar自定义返回按钮
来源:互联网 发布:淘宝 宝贝分类 编辑:程序博客网 时间:2024/04/25 17:37
1
[self.navigationController pushViewController:self.bView animated:YES];
一开始想当然的,在B视图的viewDidLoad里直接使用:
1
self.navigationItem.backBarButtonItem.title = @"back";
来更改后退按钮标题,结果后退后,发现A视图的导航栏标题也变成“back”了。
于是网上搜了一下,别人推荐在B视图的viewDidLoad/viewWillAppear里使用:
123
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 ,the navigation bar displays that item.viewcontroller has a valid item in itsbackBarButtonItem property - 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:UIBarButtonItemStyleBord ered target:nilaction:nil];
[self.navigationItem setBackBarButtonItem:backItem];
[backItem release];
[self.navigationController pushViewController:self.bView animated:YES];转载自:http://zgia.net/?p=306
- UINavigationBar自定义返回按钮
- UINavigationBar自定义返回按钮
- 自定义UINavigationBar返回按钮
- IOS UINavigationBar 自定义返回按钮
- IOS 自定义UINavigationBar返回按钮
- UINavigationBar自定义返回按钮的设置
- 不通过push,给viewcontroller自定义UINavigationBar,并加上返回按钮
- 自定义UINavigationBar和按钮
- 修改返回按钮 标题 (UINavigationBar)
- 修改UINavigationBar的返回按钮
- UINavigationBar自定义背景以及按钮
- UINavigationBar自定义背景以及按钮
- UINavigationBar 设置透明 和去掉返回按钮
- UINavigationBar属性及返回按钮更改小结
- UINavigationBar属性及返回按钮更改小结
- UINavigationBar属性及返回按钮更改小结
- UINavigationBar自定义导航栏背景和按钮
- UINavigationBar自定义导航栏背景和按钮
- 由scroll view引发的一系列小零碎
- theano tutorial学习笔记(一)
- Logistic Regression笔记
- CTreeCtrl带CHECKBOX属性,实现联动效果(点击父节点全部子节点被选中)
- 网络爬虫Python试验
- UINavigationBar自定义返回按钮
- Set Matrix Zeroes
- Java基础知识学习
- HDU 1114 Piggy-Bank (完全背包)
- 背包问题 II
- FZU-2202-犯罪嫌疑人 -10.1训练赛
- linux 常用快捷键
- [iOS进阶]XMPPFramework 学习小结
- spring整合struts2、mybatis的配置