我是一个相对新手的iOS开发者,正在处理别人的项目。我注意到似乎有各种不同的方法来展示视图。我想知道是否有人可以简要概述一下各种展示视图的方式,以及何时使用哪种方式,因为它们都似乎可以很好地工作。
例如,我遇到的一段代码做了这样的事情:
使用LLDB检查childViewController,这两个命令都返回nil: po self.parentViewController (这是nil) po self.presentingViewController (这是nil)
在其他地方,我看到过类似的内容:
例如,我遇到的一段代码做了这样的事情:
[parentView addSubview:childViewController.view];
[parentView bringSubviewToFront:childViewController.view];
使用LLDB检查childViewController,这两个命令都返回nil: po self.parentViewController (这是nil) po self.presentingViewController (这是nil)
在其他地方,我看到过类似的内容:
[parentView addSubview:childViewController.view];
[self addChildViewController:childViewcontroller];
此外,我在其他地方看到过类似这样的事情:
UIViewController *childViewController = [[SomeChildController alloc] init];
[self presentViewController:childViewController animated:YES completion:^(void){}];
有时您可以拥有一个父视图控制器或呈现视图控制器(如果您希望),而其他时候则不需要。 有这么多选项来呈现视图,您如何决定其中一种,或在何时使用哪种?
presentViewController
一样有效,那么你为什么需要使用presentViewController
呢? - Logicsaurus RexiOS视图控制器编程指南
(https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html)。这应该回答你大部分关于“为什么使用视图控制器?”的问题。 - Robotic Cat