这两个方法都是必须要ViewController, 是建立在UINavigationController之上的。

SQLiteViewController *baSQLiteViewController = [[SQLiteViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:baSQLiteViewController];
[self.window addSubview:nav.view];

推出视图push,下一页面会自动添加返回按钮
InforViewController *baInforViewController = [[InforViewController alloc] init];
[self.navigationController pushViewController:baInforViewController animated:YES];

以Modal方式推出一个视图,弹出的视图没有返回按钮,需要自己添加
NewDataViewController *baNewViewController = [[NewDataViewController alloc] init];
UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:baNewViewController];
[self.navigationController presentModalViewController:baNavigation animated:YES];
[baNewViewController release];
[baNavigation release];

为弹出视图添加返回按钮
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(returnView)];

返回方法
- (void)returnView

{
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

总结:

1 将需要present(需要弹出来的)的ViewController先添加加到一个新的UINavigationController的RootView中,例如

NewDataViewController *baNewViewController = [[NewDataViewController alloc] init]; //需要弹出的ViewController
UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:baNewViewController];//实例化一个NavigationController对象,这个对象使用将要弹出ViewController作为RootView Controlller初始化。

2. 然后present这个UINavigationController,接着就可以继续push了,当返回到present还可以缩回去

右侧进入

BaseInfoEdit *View = [[BaseInfoEdit alloc] initWithNibName:@"BaseInfo" bundle:nil];

[self.navigationController pushViewController:View animated:YES];

返回方法

[self.navigationController popViewControllerAnimated:YES];

下方进入

OilRecordAdd *View = [[OilRecordAdd alloc] initWithNibName:@"OilRecordDetail" bundle:nil];

[self.navigationController presentModalViewController:Nav animated:YES];

返回方法

[self.navigationController dismissModalViewControllerAnimated:YES];

leftBarButtonItem和rightBarButtonItem设置的是本级页面上的BarButtonItem,
backBarButtonItem设置的是下一级页面上的BarButtonItem
比如:两个ViewController,主A和子B,我们想在A上显示“刷新”的右BarButton,B上的BackButton显示为“撤退”
就应该在A的viewDidLoad类似方法中写:

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStylePlain target:self action:nil];

self.navigationItem.rightBarButtonItem = refreshButton;

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"撤退" style:UIBarButtonItemStylePlain target:self action:nil];
self.navigationItem.backBarButtonItem = cancelButton;

B不需要做任何处理
然后A push B就可以了

转载于:https://www.cnblogs.com/junxiaohu/archive/2013/04/07/3003515.html

push与presentModal的 用法详解(转)相关推荐

  1. 优先队列priority_queue 用法详解

    优先队列priority_queue 用法详解 优先队列是队列的一种,不过它可以按照自定义的一种方式(数据的优先级)来对队列中的数据进行动态的排序 每次的push和pop操作,队列都会动态的调整,以达 ...

  2. sizeof,strlen用法详解

    sizeof 前向声明: sizeof,一个其貌不扬的家伙,引无数菜鸟竟折腰,小虾我当初也没少犯迷糊,秉着"辛苦我一个,幸福千万人"的伟大思想,我决定将其尽可能详细的总结一下. 但 ...

  3. highlight.js css,JS库之Highlight.js的用法详解

    下载到本地后,新建个页面测试 1.在head中加入css和js的引用 highlight hljs.initHighlightingOnLoad(); 2.添加对应要显示的内容 # 读取文件内容 de ...

  4. #pragma pack 用法详解

    #pragma pack 用法详解 pack为struct.union和class等的成员对齐指定字节边界,与编译选项(属性 -> 配置属性 -> C/C++ ->代码生成 -> ...

  5. c++ stack用法详解

    c++ set用法详解 c++ stack用法详解 stack stack常用操作 例题 stack 栈是基本的数据结构之一,特点是先进后出,就如开进死胡同的车队,先进去的只能最后出来. 在c++ 中 ...

  6. GitHub新手用法详解【适合新手入门-建议收藏!!!】

    目录 什么是Github,为什么使用它? 一.GitHub账号的注册与登录 二. gitbash安装详解 1.git bash的下载与安装 2.git常用命令 3. Git 和 GitHub 的绑定 ...

  7. C++队列queue用法详解

    一.定义 queue是一种容器转换器模板,调用#include< queue>即可使用队列类. 二.queue初始化 queue<Type, Container> (<数 ...

  8. python argv 详解_Python3 sys.argv[ ]用法详解

    sys.argv[]说白了就是一个从程序外部获取参数的桥梁,这个"外部"很关键,因为我们从外部取得的参数可以是多个,所以获得的是一个列表(list),也就是说sys.argv其实可 ...

  9. oracle中的exists 和 not exists 用法详解

    from:http://blog.sina.com.cn/s/blog_601d1ce30100cyrb.html oracle中的exists 和 not exists 用法详解 (2009-05- ...

最新文章

  1. C++拾趣——STL容器的插入、删除、遍历和查找操作性能对比(Windows VirtualStudio)——遍历和删除
  2. 全美第二的机器人项目核心数学课免费开放,院长亲自授课,作业讲义全同步...
  3. Oracle数据库教程
  4. kong 网关日志格式修改
  5. 检测网络状态的工具类
  6. c语言综合模拟测试题答案,【C语言指针模拟测试题_答案】
  7. sql必知必会的数据初始化
  8. 学号:201621123032 《Java程序设计》第3周学习总结
  9. Sonar问题及解决方案汇总
  10. python获取服务器端的时间
  11. 技术人员的会议优化记录
  12. 【转】推荐几个免费下载破解软件的网站以及系统
  13. 苹果个人开发者账号审核
  14. 【笃行】Button的选中与改变
  15. 揭开 Flutter 跨平台开源框架的神秘面纱
  16. RuntimeError: mat1 and mat2 shapes cannot be multiplied (5760x6 and 128x4)
  17. POI和Java Excel Api导入导出----详细到你不敢相信
  18. Tableau 读书笔记
  19. std::bitset使用
  20. 解决IDEA占用C盘空间过大的问题

热门文章

  1. archlinux cn源
  2. php 开发 比 java 快_PHP 比 Java 的开发效率高在哪?
  3. 想轻松入门Python编程,这10个经典案例你还不知道嘛?
  4. Python基础编程——字典的创建
  5. python 类变量修改_python中类变量与成员变量的使用注意点总结
  6. 二分类变量相关性分析spss_spss:两个有序分类变量的相关分析『kendallstau-b相关系数』...
  7. ab plc编程软件_三菱PLC原装和高仿怎么区分?PLC仿真软件和编程软件一样吗?
  8. 教你C语言实现通讯录的详细代码
  9. centos7部署DM8
  10. 求n!(n的阶乘)和1!+2!+....n! (阶乘求和) ----C语言实现