问题描述
我知道有三种方法可以在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 ownNavigationCotrollers
orTabControllers
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有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!