假设您有一个应用程序,您确信始终显示一个 UINavigationController
,并且我需要从该 Controller 外部以模态方式显示另一个 View Controller (例如:因为我使用命令模式,我不想向它提供对 View Controller 的引用)。
是否有一种安全的方法来获取“根”导航 Controller ,并调用其 presentModalViewController:animated
方法?
我尝试使用[UIApplication sharedApplication].keyWindow.rootViewController
但是I figured out that it was nil during an alert .
最佳答案
您使用的是 Storyboard还是单独的 xib?
如果您使用单独的 xib,那么您将在 applicationDidFinishLaunching
中设置 UINavigationController
。
您可以将导航 Controller 设置为应用程序委托(delegate)的属性。
然后,您可以通过获取单例应用程序委托(delegate)并从中获取导航 Controller 属性,从任何地方访问 UINavigationController。
关于objective-c - 如何使用当前的模态视图 Controller 在 View Controller 之外呈现模态视图 Controller :animated?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13860872/