Difference between presentModalViewController and presentViewController?

别等时光非礼了梦想. 提交于 2019-12-03 11:45:14

问题


In iOS 5 SDK, there're two methods of UIViewController, presentModalViewController:animated: and 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.

If I use a presentModalViewController:animated in iOS 5, will it causes a bug?

Are they functionally-same?


回答1:


They seem to do the same thing as apple documentation points 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.

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.




回答2:


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):

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


来源:https://stackoverflow.com/questions/8365263/difference-between-presentmodalviewcontroller-and-presentviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!