在不知道当前视图控制器的情况下呈现模态控制器? [英] Presenting a modal controller without knowing the current view controller?
问题描述
有没有办法在不知道可见视图控制器视图是什么的情况下以模态方式呈现视图控制器?基本上有点像你会在任何时间点显示警报视图。
Is there a way to present a view controller modally without knowing what the visible view controller view is? Basically sort of like you would show an alert view at any points in time.
我希望能够做到这样的事情:
I would like to be able to do something like:
MyViewController *myVC = [[MyViewController alloc] init];
[myVC showModally];
我希望能够从应用中的任何地方拨打此电话,并将其显示在最佳。我不想关心当前的视图控制器是什么。
I'd like to be able to call this from anywhere in the app, and have it appear on top. I don't want to care about what the current view controller is.
我打算用它来显示登录提示。我不想使用警报视图,我也不希望在整个应用程序中都有登录演示代码。
I plan to use this to show a login prompt. I don't want to use an alert view, and I also don't want to have login presentation code throughout the app.
对此有何看法?或者有没有更好的方法来实现这一目标?我应该只实现自己的机制,只是在窗口顶部放置一个视图吗?
Any thoughts on this? Or is there maybe a better way to achieve this? Should I just implement my own mechanism and just place a view on top of the window?
推荐答案
嗯,你可以关注链。
从开始[UIApplication sharedApplication] .delegate.window.rootViewController
。
在每个视图控制器上执行以下一系列测试。
At each view controller perform the following series of test.
如果 [viewController isKindOfClass:[UINavigationController class]]
,然后进入 [(UINavigationController *)viewController topViewController]
。
如果 [viewController isKindOfClass:[UITabBarController class]]
,然后进入 [(UITabBarController *)viewController selectedViewController]
。
如果 [viewController presentViewController]
,则继续 [viewController presentViewController]
。
这篇关于在不知道当前视图控制器的情况下呈现模态控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!