iOS 深入理解UINavigationController 和 UIViewController 之间的关系
创建三个类
- BasicViewController : UIViewController
- SecondViewController : UIViewController
- 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:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Override point for customization after application launch.
- BasicViewController *basicViewController = [BasicViewController new];//实例化内存后,_parentViewController-->nil
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:basicViewController];
- // self.window.rootViewController = basicViewController.parentViewController;
- self.window.rootViewController = navigationController;
- [self.window makeKeyAndVisible];
- return YES;
- }
等价于
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Override point for customization after application launch.
- BasicViewController *basicViewController = [BasicViewController new];//实例化内存后,_parentViewController-->nil
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:basicViewController];
- self.window.rootViewController = basicViewController.parentViewController; //不可以注释上一句,因为上一句是为_parentViewController实例化
- // self.window.rootViewController = navigationController;
- [self.window makeKeyAndVisible];
- return YES;
- }
分配内存如图 
iOS 深入理解UINavigationController 和 UIViewController 之间的关系的更多相关文章
- UIWindow,UINavigationController与UIViewController之间的关系
UIWindow,UINavigationController与UIViewController之间的关系 虽然每次你都用UINavigationController与UIWindow,但你不一定知道 ...
- async/await到底该怎么用?如何理解多线程与异步之间的关系?
前言 如标题所诉,本文主要是解决是什么,怎么用的问题,然后会说明为什么这么用.因为我发现很多萌新都会对之类的问题产生疑惑,包括我最初的我,网络上的博客大多知识零散,刚开始看相关博文的时候,就这样.然后 ...
- 如何理解Nginx, WSGI, Flask之间的关系
概览 之前对 Nginx,WSGI(或者 uWSGI,uwsgi),Flask(或者 Django),这几者的关系一存存在疑惑.通过查阅了些资料,总算把它们的关系理清了. 总括来说,客户端从发送一个 ...
- angular源码阅读,依赖注入的原理:injector,provider,module之间的关系。
最开始使用angular的时候,总是觉得它的依赖注入方式非常神奇. 如果你跳槽的时候对新公司说,我曾经使用过angular,那他们肯定会问你angular的依赖注入原理是什么? 这篇博客其实是angu ...
- IOS关于UIViewController之间的切换
IOS关于UIViewController之间的切换 1.NavigationController切换UIViewController的两种方式 方法一右侧进入 1 SecondViewControl ...
- 【iOS开发-72】设置状态栏的两种方式、程序生命周期以及更好地理解几大类(对象)之间的关系
(1)设置状态栏的2种方式 --第一种方式就是我们在控制器中设置,系统默认就是交给视图控制器去管理的,这样不同视图控制器能够自己定义不同的状态栏例如以下: -(BOOL)prefersStatusBa ...
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
- [转]iOS学习之UINavigationController详解与使用(三)ToolBar
转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...
- [转]iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
转载地址:http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINav ...
随机推荐
- IE安全分析
IE安全问题,这个话题似乎很古老了,但是问题又是层出不穷~ 对于IE的安全,我个人认为有两点需要关注,一个是上网的安全,二个是IE解析代码的安全 对于IE上网安全,这是最基本的,也是最常用的了 附上一 ...
- Yii2框架与MongoDB拓展、Redis拓展的安装流程
@author 周煦辰 2016-03-21 这段时间新上了一个项目,使用的是Yii2框架.这里记录一下Yii2框架.Yii2-Mongo拓展.Yii2-Redis拓展等的安装流程.因为使用的系统是W ...
- 弹出框二 之 bootbox.js
1.可以通过Nuget下载 2.引入 jquery bootstrap bootbox.js 3.使用 $(function () { //bootbox.alert("确认删除" ...
- linux安装-版本选择-终极决定
选用64位或32位的版本,注意看硬件: 内存大于4G的用64位, 小于4G的用32位 同时, 64位的版本在软件源, 软件的兼容性等问题. ----------------------------- ...
- matlab求解相关系数
最近收到一项新任务,要求两个矩阵的相关系数,说白了就是转换成向量两两计算.本来这个工作我是想自己写个小程序搞定的,但是大家纷纷反映matlab自带了此项功能,本着活到老学到老的心态,我开始查找这个函数 ...
- ProgressBar样式(转)
普通圆形ProgressBar 该类型进度条也就是一个表示运转的过程,例如发送短信,连接网络等等,表示一个过程正在执行中. 一般只要在XML布局中定义就可以了. <progressBar and ...
- ZOJ 3201 Tree of Tree
树形DP.... Tree of Tree Time Limit: 1 Second Memory Limit: 32768 KB You're given a tree with weig ...
- 【C语言入门教程】2.2 常量 与 变量
2.2 常量 与 变量 顾名思义,常量是运算中不能改变数值的数据类型,变量是可改变数值的数据类型.根据需要,可将一些在程序中不必改变数值的类型定义为常量,这样也可避免因修改数值造成程序错误.任何改变常 ...
- 【C语言入门教程】4.7 指针的地址分配 - mallocl(), free()
指针变量可指向任何类型的变量,在处理过程中,指针变量指向的变量通过传递变量的地址来实现,指针变量的取值是内存的地址,这个地址应当是安全的,不可以是随意的.否则,写入内存单元的值将使得已存放的数据或程序 ...
- iOS resign code with App Store profile and post to AppStore
http://stackoverflow.com/questions/17545452/ios-resign-code-with-app-store-profile-and-post-to-appst ...