presentModalViewController和presentViewController之间的区别?

时间:2011-12-03 03:28:46

标签: iphone ios viewcontroller

在iOS 5 SDK中,有两种方法是UIViewController,presentModalViewController:animated:和presentViewController:animated:completion:。

这两种方法有什么区别?

文档说:nowViewController:animated:completion:方法是从iOS 5.0开始呈现模态视图的首选方式。

如果我在iOS 5中使用presentModalViewController:动画,它会导致错误吗?

它们功能相同吗?

2 个答案:

答案 0 :(得分:24)

它们似乎与apple documentation指出的一样,因为iOS 5.0 presentViewController是呈现视图控制器的首选方式,似乎presentViewController现在让你拥有完成处理程序,而在你没有完成之前。

并且没有旧的presentModalViewController在iOS 5.0上应该没问题,如果它导致了一个对所有旧应用程序都有问题但不会向后兼容的错误。此外,现在使用presentViewController,您可以获得有关viewController层次结构的更多信息,因为我们拥有presentingViewControllerpresentedViewController属性。

答案 1 :(得分:13)

另一个重要的注意事项是,将来不推荐使用presentModalViewController,如UIKit框架的UIViewController.h(Xcode版本4.3.1)所述:

// 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;