hildViewController和presentModelV

hildViewController和presentModelV

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

问题描述

我知道有三种方法可以在iOS中更改视图

I know there are three ways to change the view in iOS

1。

[self addChildViewController:thirdViewController];
[contentView addSubview:thirdViewController.view];

2。

First * sVC = [[First alloc] initWithNibName:@"First" bundle:[NSBundle mainBundle]];
[self presentModalViewController:sVC animated:YES];

3。

MyViewController *sampleViewController = [[[MyViewController alloc]initWithXXX] autorelease];
[self.navigationController pushViewController: sampleViewController animated:true];

pushViewController需要导航控制器,我理解。但是,什么时候使用addChildViewController和presentModalViewController?

pushViewController requires the navigation controller, which I understand. However, when to use addChildViewController and presentModalViewController??

推荐答案

这些是完全不同的四种实现

These are four totally different implementations


  • addChildViewController 在iOS5中用于执行viewController包含,这将使您轻松创建自己的 NavigationCotrollers TabControllers 仅在iOS5中可用

  • addChildViewController is used in iOS5 to do viewController containment, this will enable you to easily create your own NavigationCotrollers or TabControllers its only available in iOS5

addSubview 是这三个中的最低级别,这只会将视图添加到另一个视图,作为孩子

addSubview is the lowest level of the three, this will just add a view to another view, as a child

presentModalViewController 用于在屏幕上以模态方式呈现viewController,从而覆盖旧的

presentModalViewController is used to present a viewController modally on the screen, hence overwriting the old one

pushViewController UINavigationController 中用于将新的ViewController推送到viewcontrollers堆栈,

pushViewController used in UINavigationController to push a new ViewController to the viewcontrollers stack,

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

08-24 18:36