ios presentModalViewController 和presentViewController 的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8365263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between presentModalViewController and presentViewController?
提问by YuAo
In iOS 5 SDK, there're two methods of UIViewController, presentModalViewController:animated: and presentViewController:animated:completion:.
在 iOS 5 SDK 中,UIViewController 有两种方法,presentModalViewController:animated: 和 presentViewController:animated:completion:。
What's the difference between these two method?
这两种方法有什么区别?
The documentation says: The presentViewController:animated:completion: method is the preferred way to present a modal view as of iOS 5.0.
文档说:presentViewController:animated:completion: 方法是从 iOS 5.0 开始呈现模态视图的首选方式。
If I use a presentModalViewController:animated in iOS 5, will it causes a bug?
如果我在 iOS 5 中使用 presentModalViewController:animated,它会导致错误吗?
Are they functionally-same?
它们在功能上相同吗?
采纳答案by Daniel
They seem to do the same thing as apple documentationpoints out, as of iOS 5.0 presentViewController
is the preferred way to present view controllers, it seems that presentViewController
now lets you have a completion handler, whereas before you did not have that.
它们似乎与苹果文档指出的一样,因为 iOS 5.0presentViewController
是呈现视图控制器的首选方式,现在似乎presentViewController
让您拥有完成处理程序,而在此之前您没有。
And no the older presentModalViewController
should be fine on iOS 5.0, if it caused a bug that would be a problem for all the older apps and would not be very backward compatible. Furthermore it seems that now with presentViewController
you can get a lot more info about the viewController hierarchy as we have presentingViewController
, presentedViewController
properties.
没有旧版本presentModalViewController
在 iOS 5.0 上应该没问题,如果它导致了一个错误,这对所有旧应用程序都是一个问题,并且不会非常向后兼容。此外,它似乎现在presentViewController
你可以得到很多详细信息有关的viewController层次,因为我们有presentingViewController
,presentedViewController
性质。
回答by Dat Nguyen
Another important note is that presentModalViewController will be deprecated in the future, as mentioned in the UIViewController.h of the UIKit framework (Xcode version 4.3.1):
另一个重要的注意事项是,presentModalViewController 将来会被弃用,如 UIKit 框架(Xcode 版本 4.3.1)的 UIViewController.h 中所述:
// Display another view controller as a modal child. Uses a vertical sheet transition if animated.This method has been replaced by presentViewController:animated:completion:
// It will be DEPRECATED, plan accordingly.
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;
// Dismiss the current modal child. Uses a vertical sheet transition if animated. This method has been replaced by dismissViewControllerAnimated:completion:
// It will be DEPRECATED, plan accordingly.
- (void)dismissModalViewControllerAnimated:(BOOL)animated;