创建三个类

  1. BasicViewController : UIViewController
  2. SecondViewController : UIViewController
  3. ThirdViewController : UIViewController

然后我们在BasicViewController .m文件中push一个viewController: 
SecondViewController *svc = [SecondViewController new]; 
[self.navigationController pushViewController:svc animated:true]; 
在SecondViewController.m文件中pop出viewController: 
[self.navigationController popViewControllerAnimated:true]

问题就来了, 
push和pop是同一个viewController,那为什么用self.navigationController 就可以知道了

其中在AppDelegate.m:

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  4. // Override point for customization after application launch.
  5. BasicViewController  *basicViewController = [BasicViewController new];//实例化内存后,_parentViewController-->nil
  6. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:basicViewController];
  7. // self.window.rootViewController = basicViewController.parentViewController;
  8. self.window.rootViewController = navigationController;
  9. [self.window makeKeyAndVisible];
  10. return YES;
  11. }

等价于

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  4. // Override point for customization after application launch.
  5. BasicViewController  *basicViewController = [BasicViewController new];//实例化内存后,_parentViewController-->nil
  6. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:basicViewController];
  7. self.window.rootViewController = basicViewController.parentViewController; //不可以注释上一句,因为上一句是为_parentViewController实例化
  8. // self.window.rootViewController = navigationController;
  9. [self.window makeKeyAndVisible];
  10. return YES;
  11. }

分配内存如图 

iOS 深入理解UINavigationController 和 UIViewController 之间的关系的更多相关文章

  1. UIWindow,UINavigationController与UIViewController之间的关系

    UIWindow,UINavigationController与UIViewController之间的关系 虽然每次你都用UINavigationController与UIWindow,但你不一定知道 ...

  2. async/await到底该怎么用?如何理解多线程与异步之间的关系?

    前言 如标题所诉,本文主要是解决是什么,怎么用的问题,然后会说明为什么这么用.因为我发现很多萌新都会对之类的问题产生疑惑,包括我最初的我,网络上的博客大多知识零散,刚开始看相关博文的时候,就这样.然后 ...

  3. 如何理解Nginx, WSGI, Flask之间的关系

    概览 之前对 Nginx,WSGI(或者 uWSGI,uwsgi),Flask(或者 Django),这几者的关系一存存在疑惑.通过查阅了些资料,总算把它们的关系理清了. 总括来说,客户端从发送一个 ...

  4. angular源码阅读,依赖注入的原理:injector,provider,module之间的关系。

    最开始使用angular的时候,总是觉得它的依赖注入方式非常神奇. 如果你跳槽的时候对新公司说,我曾经使用过angular,那他们肯定会问你angular的依赖注入原理是什么? 这篇博客其实是angu ...

  5. IOS关于UIViewController之间的切换

    IOS关于UIViewController之间的切换 1.NavigationController切换UIViewController的两种方式 方法一右侧进入 1 SecondViewControl ...

  6. 【iOS开发-72】设置状态栏的两种方式、程序生命周期以及更好地理解几大类(对象)之间的关系

    (1)设置状态栏的2种方式 --第一种方式就是我们在控制器中设置,系统默认就是交给视图控制器去管理的,这样不同视图控制器能够自己定义不同的状态栏例如以下: -(BOOL)prefersStatusBa ...

  7. iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

    http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...

  8. [转]iOS学习之UINavigationController详解与使用(三)ToolBar

    转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...

  9. [转]iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

    转载地址:http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINav ...

随机推荐

  1. ecshop 默认图处理

    function get_banner_path($img) { $img = empty($img) ? C('no_picture') : $img; return $img;}

  2. EF事务

    var db = this.UnitOfWork as CodeFirstDbContext; using (var tan = db.Database.BeginTransaction()) { t ...

  3. Nginx + spawn-fcgi- Ubuntu中文

    Nginx - Ubuntu中文 页面 讨论 查看源代码 历史   导航 首页 最近更改 随机页面 页面分类 帮助 编辑 编辑指南 沙盒 新闻动态 字词处理 工具 链入页面 相关更改 特殊页面 打印版 ...

  4. Bootstrap学习------Tabel

    Bootstrap的表格和Html表格大同小异,只是封装了一些css供我们使用 <table>标签必须引用class="table"基类样式,我们可以根据需求赛选需要的 ...

  5. jquery客户端验证插件

    http://www.cnblogs.com/masing/articles/2157420.html http://www.oschina.net/p/jquery+formvalidator ht ...

  6. highstock 的tooltip框里面的内容 保留两位小数的办法

    $("#flux_chart_container").highcharts('                           },            borderWidt ...

  7. Markdown 写作工具选择

    Markdown 写作工具选择 候选产品 参考了少数派网站 markdown 写作工具2015年度盘点 http://sspai.com/32483, Windows 下 Markdown 的编辑工具 ...

  8. spring配置文件详解--真的蛮详细

    spring配置文件详解--真的蛮详细   转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常 ...

  9. JavaWeb学习总结(五十三)——Web应用中使用JavaMail发送邮件

    现在很多的网站都提供有用户注册功能, 通常我们注册成功之后就会收到一封来自注册网站的邮件.邮件里面的内容可能包含了我们的注册的用户名和密码以及一个激活账户的超链接等信息.今天我们也来实现一个这样的功能 ...

  10. [AngularJS] 入门

    什么是AngularJS AngularJS是Google开源的一款JavaScript MVC框架,弥补了HTML在构建应用方面的不足, 其通过使用指令(directives)结构来扩展HTML词汇 ...