IOS 改变Navigation的返回按钮
两个办法:
1, 手动为每一个UIViewController添加navigationItem的leftButton的设置代码
2,为UINavigationController实现delegate,在pop和push的时候改变当前和上一页的navigationItem.title
以下是封装的一些基础方法,供参考:
+ (void) navigationItem:(UINavigationItem*)navigationItem
setTitle:(NSString*)title;
+ (void) navigationItem:(UINavigationItem*)navigationItem
setBackButton:(NSString*)title
addTarget:(id)target
action:(SEL)action;
+ (void) navigationItem:(UINavigationItem*)navigationItem
setImage:(NSString*)imageString;
无奈之下,只好研读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 backBarButtonItemproperty, 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了。
eg:
UIBarButtonItem*backItem=[[UIBarButtonItemalloc]init];
backItem.title=@"戻る";
self.navigationItem.backBarButtonItem=backItem;
[backItem release]
==============
新方案:
self.navigationController.navigationBar.topItem.title=self.message;
self.navigationController.navigationBar.tintColor=[UIColorblackColor];
UIBarButtonItem*backButton = [[UIBarButtonItemalloc] initWithTitle:@" fan hui "style:UIBarButtonItemStyleBorderedtarget:selfaction:@selector(PopViewController)];
self.navigationItem.leftBarButtonItem= backButton;
以上转自:http://hi.baidu.com/myyuchong/item/1e6db306c5d34de1359902a1
PS:在第三种情况的时候,自动创建的返回按钮只取了A视图的title值,其他属性并没有复制,看来要改变颜色等别的属性还得自定义一个返回按钮啊
IOS 改变Navigation的返回按钮的更多相关文章
- IOS 改变导航栏返回按钮的标题
IOS 改变导航栏返回按钮的标题 下午又找到了一个新的方法 这个方法不错 暂时没有发现异常的地方. 新写的App中需要使用UINavigationController对各个页面进行导航,但由于第一 ...
- ios 修改导航条返回按钮
ios 修改导航条返回按钮 方式一:使用系统的:可以更改系统的文字:以及通过设置导航条的颜色来达到预期的效果 UIBarButtonItem *backBtns = [[UIBarButtonItem ...
- iOS项目导航栏返回按钮
最近iOS项目中要求导航栏的返回按钮只保留那个箭头,去掉后边的文字,在网上查了一些资料,最简单且没有副作用的方法就是 [[UIBarButtonItem appearance] setBackButt ...
- iOS学习—— UINavigationController的返回按钮与侧滑返回手势的研究
侧滑返回手势是从iOS7开始增加的一个返回操作,经历了两年时间估计iPhone用户大部分都已经忽略了屏幕左上角那个碍眼的back按钮了.之前在网上搜过有关侧滑手势的技术博客,发现大多比较散乱,甚至有很 ...
- 转载 iOS拦截导航栏返回按钮事件的正确方式
原文链接:http://www.jianshu.com/p/25fd027916fa 当我们使用了系统的导航栏时,默认点击返回按钮是 pop 回上一个界面.但是在有时候,我们需要在点击导航栏的返回按钮 ...
- ios 修改导航栏返回按钮的图片
修改导航栏返回按钮的图片 方法1: [UINavigationBar appearance].backIndicatorTransitionMaskImage = [UIImage imageName ...
- iOS拦截导航栏返回按钮事件的正确方式
当我们使用了系统的导航栏时,默认点击返回按钮是 pop 回上一个界面.但是在有时候,我们需要在点击导航栏的返回按钮时不一定要 pop 回上一界面,比如一个视频播放界面,进入横屏后,默认点击返回按钮仍然 ...
- iOS拦截导航栏返回按钮事件的正确方式(二)
当我们使用了系统的导航栏时,默认点击返回按钮是 pop 回上一个界面.但是在有时候,我们需要在点击导航栏的返回按钮时不一定要 pop 回上一界面,比如一个视频播放界面,进入横屏后,默认点击返回按钮仍然 ...
- 拦截iOS系统导航栏返回按钮事件-三种方法
方法一:在dealloc里面书写监听事件,因为只有pop才会调用dealloc,push不会掉用 - (void)dealloc {YLLog(@"123"); } 方法二:在- ...
随机推荐
- 【线程池】ExecutorService与quartz搭配出现的问题
问题描述: 使用quartz定时推送微信公众号模板消息,一分钟推送一次,定时器里面使用了一个ExecutorService线程池,大小为5个. 批量获取数据之后,全部数据都被分配到n/5的线程池里面等 ...
- destoon 配置文件config.inc.php参数说明
$CFG['db_host']数据库服务器,可以包括端口号,一般为localhost $CFG['db_user']数据库用户名,一般为root $CFG['db_pass']数据库密码 $CFG[' ...
- 自动设置IP地址bat脚本
自动获取IP及DNS: netsh interface ip set address name="本地连接" source=dhcpnetsh interface ip set d ...
- Spring boot 中Spring data JPA的应用(一)
最近一直在研究Spring Boot,今天为大家介绍下Spring Data JPA在Spring Boot中的应用,如有错误,欢迎大家指正. 先解释下什么是JPA JPA就是一个基于O/R映射的标准 ...
- kettle-学习参考
一 关于Kettle Kettle是一款国外开源的ETL工具,纯java编写,数据抽取高效稳定的数据迁移工具.Kettle中有两种脚本文件,transformation和job,transf ...
- jubeeeeeat(网络流)
jubeeeeeat 总时间限制: 1000ms 内存限制: 256000kB 描述 众所周知,LZF很喜欢打一个叫Jubeat的游戏.这是个音乐游戏,游戏界面是4×4的方阵,会根据音乐节奏要求玩 ...
- MySQL基本命令和常用数据库对象
MySQL基本命令: 连接远程主机的MySQL服务(为了保证安全性,执行下面命令时,可以省略-p后面的密码,执行命令后系统会提示输入密码) mysql -p 密码 -u 用户名 -h 主机地址 --d ...
- NetBeans无法使用编码GBK安全地打开该文件
今天用NetBeans打开包含路径里面的UTF-8编码的文件时,提示:NetBeans无法使用编码GBK安全地打开该文件. 后来在网上搜索找到了解决方案,原文地址:http://qdjinxin.it ...
- tomcat6-endpoint设计
之前写的一个ppt 搬到博客来
- uiautomatorviewer打不开
uiautomatorviewer打不开: 因为之前我下载的jdk版本为10,后来将jdk版本改为8之后就可以打开了.