两个办法:

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的返回按钮的更多相关文章

  1. IOS 改变导航栏返回按钮的标题

    IOS 改变导航栏返回按钮的标题   下午又找到了一个新的方法 这个方法不错 暂时没有发现异常的地方. 新写的App中需要使用UINavigationController对各个页面进行导航,但由于第一 ...

  2. ios 修改导航条返回按钮

    ios 修改导航条返回按钮 方式一:使用系统的:可以更改系统的文字:以及通过设置导航条的颜色来达到预期的效果 UIBarButtonItem *backBtns = [[UIBarButtonItem ...

  3. iOS项目导航栏返回按钮

    最近iOS项目中要求导航栏的返回按钮只保留那个箭头,去掉后边的文字,在网上查了一些资料,最简单且没有副作用的方法就是 [[UIBarButtonItem appearance] setBackButt ...

  4. iOS学习—— UINavigationController的返回按钮与侧滑返回手势的研究

    侧滑返回手势是从iOS7开始增加的一个返回操作,经历了两年时间估计iPhone用户大部分都已经忽略了屏幕左上角那个碍眼的back按钮了.之前在网上搜过有关侧滑手势的技术博客,发现大多比较散乱,甚至有很 ...

  5. 转载 iOS拦截导航栏返回按钮事件的正确方式

    原文链接:http://www.jianshu.com/p/25fd027916fa 当我们使用了系统的导航栏时,默认点击返回按钮是 pop 回上一个界面.但是在有时候,我们需要在点击导航栏的返回按钮 ...

  6. ios 修改导航栏返回按钮的图片

    修改导航栏返回按钮的图片 方法1: [UINavigationBar appearance].backIndicatorTransitionMaskImage = [UIImage imageName ...

  7. iOS拦截导航栏返回按钮事件的正确方式

    当我们使用了系统的导航栏时,默认点击返回按钮是 pop 回上一个界面.但是在有时候,我们需要在点击导航栏的返回按钮时不一定要 pop 回上一界面,比如一个视频播放界面,进入横屏后,默认点击返回按钮仍然 ...

  8. iOS拦截导航栏返回按钮事件的正确方式(二)

    当我们使用了系统的导航栏时,默认点击返回按钮是 pop 回上一个界面.但是在有时候,我们需要在点击导航栏的返回按钮时不一定要 pop 回上一界面,比如一个视频播放界面,进入横屏后,默认点击返回按钮仍然 ...

  9. 拦截iOS系统导航栏返回按钮事件-三种方法

    方法一:在dealloc里面书写监听事件,因为只有pop才会调用dealloc,push不会掉用 - (void)dealloc {YLLog(@"123"); } 方法二:在- ...

随机推荐

  1. jQuery获取动态添加的元素,live和on的区别

    今天给大家说一下如果用jQuery获取动态添加的元素,通常如果你在网页上利用jQuery添加一个元素,那么用平常的jQuery获取元素的方法无效的获取不到的.可以用以下的方法获取动态元素!假设我们现在 ...

  2. zookeeper伪集群(一)

    Zookeeper的安装和配置十分简单, 既可以配置成单机模式, 也可以配置成伪集群模式.集群模式. 本人将对伪集群.集群进行重点介绍: 铺垫: 1.集群必须是奇数(2N+1),伪集群和集群一致. 2 ...

  3. str 方法总结整理

    #!/usr/bin/env python #Python 3.7.0 字符串常用方法 __author__ = "lrtao2010" #capitalize 将字符串的首字符改 ...

  4. python中文件操作的其他方法

    前面介绍过Python中文件操作的一般方法,包括打开,写入,关闭.本文中介绍下python中关于文件操作的其他比较常用的一些方法. 首先创建一个文件poems: p=open('poems','r', ...

  5. for_each_node(node)

    遍历各个pg_data_t节点. 1.定义在include/linux/nodemask.h中 /* * Bitmasks that are kept for all the nodes. */ en ...

  6. nrf528xx bootloader 模块介绍(转载)

    转载https://www.cnblogs.com/rfnets/p/8205521.html 1. bootloader 的基本功能: 启动应用 几个应用之间切换 初始化外设 nordic nrf5 ...

  7. SDUSToj第十一次作业源代码格式问题

    Problem I: 源代码的格式 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 1471  Solved: 634 [Submit][Status][W ...

  8. Leetcode27--->Remove Element(移除数组中给定元素)

    题目:给定一个数组array和一个值value,移除掉数组中所有与value值相等的元素,返回新的数组的长度:要求:不能分配额外的数组空间,且必须使用原地排序的思想,空间复杂度O(1); 举例: Gi ...

  9. selenium非常好的资料收集

    非常全的中文资料:http://qi-ling2006.iteye.com/ http://blog.csdn.net/qq744746842/article/details/49926917

  10. 创建sql作业(JOB)

    在SQL Server日常需求处理中,会遇到定时执行或统计数据的需求,这时我们可以通过作业(JOB)来处理,从而通过代理的方式来实现数据的自动处理.一下为SQL Server中创建作业的脚本,供大家参 ...