有没有办法从 AppDelegate 获取当前 View Controller ?我知道有 rootViewController,但这不是我要找的。p>
最佳答案
如果您的应用的 Root View Controller 是 UINavigationController
,您可以这样做:
((UINavigationController*)appDelegate.window.rootViewController).visibleViewController;
同样,如果它是 UITabBarController
你可以这样做:
((UITabBarController*)appDelegate.window.rootViewController).selectedViewController;
当然,像这样的显式转换是肮脏的。最好使用强类型自己捕获引用。
关于objective-c - AppDelegate 的当前 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9009646/