pushViewController和addSubview有什么区别 [英] what's the difference of pushViewController and addSubview

查看:50
本文介绍了pushViewController和addSubview有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过界面构建​​器创建了一个名为"YLJTestViewController"的ViewController,代码如下:

I create a ViewController named "YLJTestViewController" by interface builder ,code is like:

-(IBAction)DoneButtonPressed:(id)sender
{
    YLJTestViewController *testViewController = [[YLJTestViewController alloc]initWithNibName:@"YLJTestViewController" bundle:nil];
    [self.navigationController pushViewController:testViewController animated:YES];
    //[self.view addSubview:testViewController.view];
}

但是当我使用 [self.view addSubview:textViewController.view]; 崩溃时,却使用了 [self.navigationController pushViewController:testViewController animation:YES]; it效果很好,有什么区别?我认为它们是相同的...

but when I use [self.view addSubview:textViewController.view];it crashed,but use [self.navigationController pushViewController:testViewController animated:YES];it works well,so what's the difference?I thought they are the same...

推荐答案

pushViewController 就像在一张纸上添加一张纸,而 addSubView 就像胶水一样一张纸放在另一张纸上.

pushViewController is like adding a piece of paper onto a stack of paper, while addSubView is like gluing a piece of paper onto another paper.

被推入的视图控制器的前一个视图和新视图之间没有明确的关系(就像纸堆中的纸张仍然分开一样).父视图将保留对其子视图(例如胶水)的强烈引用.

There is no explicit relationships between the previous view and the new view of the view controller which is pushed (like the pieces of paper are still separated in the stack). While the parent view will keep a strong reference to its subviews (like glue).

这篇关于pushViewController和addSubview有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆