如何从不同的视图控制器呈现modalViewController?
我目前正在显示我的模态视图:
[self presentModalViewController:navController animated:YES];
但是,我想
[OtherViewController presentModalViewController:navController animated:YES];
因为它的一部分被另一个位于其上方的viewController隐藏并管理“自我”视图。
答案 0 :(得分:1)
它应该可行,但也许你处于一个极端的情况。
尝试向您的委托添加静态方法,如:
+ (void)presentModalViewController:(UIViewController *)viewController;
你在哪里做
[parentViewController presentModalViewController:viewController animated:YES];
并使用它直接从父VC显示模态视图。
无论如何,如果你仍有问题,请给我们一些代码:-)或你的app archi。
答案 1 :(得分:0)
它根本不起作用b / c现在在UIViewController类中声明了这样的类方法。
您正在尝试致电(请注意前面的+号):
+ (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
UIViewController类仅提供实例方法的实现(注意前面的 - 符号):
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
这应该告诉你什么?
它告诉您需要有一个指向实时OtherViewController
对象的链接才能在其上调用presentModalViewController
,否则编译器可以遵循View
层次结构