1

我试图了解容器控制器和他们的孩子之间的关系。我发现 Apple 在 presentingViewController 和 parentViewController 之间的区别有些武断。例如,我使用包含 UINavigationController 的 UITabBarController 创建了一个故事板。nav 控制器推入另一个 UIViewController,该 UIViewController 又显示一个模态视图控制器。

故事板图像可以在http://www.personal-lexicon.com/xyz/ViewControllerParentTest.png找到

通过按下每个控制器上的Show Parent Info按钮,我使用以下代码打印出它的关系。

- (IBAction)showParent:(id)sender {
const char *selfCls = class_getName(self.class);
NSLog(@"%@ = %p (%s)", self.title, self, selfCls);

const char *parentCls = class_getName(self.parentViewController.class);
NSLog(@"Parent Controller = %p (%s)", self.parentViewController, parentCls);

const char *presentingCls = class_getName(self.presentingViewController.class);
NSLog(@"Presenting Controller = %p (%s)", self.presentingViewController, presentingCls);

const char *navCls = class_getName(self.navigationController.class);
NSLog(@"Navigation Controller = %p (%s)", self.navigationController, navCls);

const char *tabCls = class_getName(self.tabBarController.class);
NSLog(@"TabBar Controller = %p (%s)\n\n", self.tabBarController, tabCls);
}

这将产生以下输出:

Root = 0x68ca810 (PTMasterViewController)
Parent Controller = 0x68ca610 (UINavigationController)
Presenting Controller = 0x0 (nil)
Navigation Controller = 0x68ca610 (UINavigationController)
TabBar Controller = 0x68ca3a0 (UITabBarController)

1st Push = 0x68d6f10 (PTMasterViewController)
Parent Controller = 0x68ca610 (UINavigationController)
Presenting Controller = 0x0 (nil)
Navigation Controller = 0x68ca610 (UINavigationController)
TabBar Controller = 0x68ca3a0 (UITabBarController)

Modal 1 = 0x68d7860 (PTMasterViewController)
Parent Controller = 0x0 (nil)
Presenting Controller = 0x68ca3a0 (UITabBarController)
Navigation Controller = 0x0 (nil)
TabBar Controller = 0x0 (nil)

Root1st Push控制器的关系是有道理的,但为什么模态控制器将 UITabBarController 显示为其呈现控制器?对我来说,这应该是第一个 Push控制器。甚至导航控制器也比标签栏控制器更有意义。

4

0 回答 0