【问题标题】:how to get currently viewing viewcontroller?如何获取当前查看的视图控制器?
【发布时间】:2014-03-18 06:47:50
【问题描述】:

当推送通知到达时,我需要从 AppDelegate 的方法 didReceiveRemoteNotification: 获取当前正在查看的 ViewController。我一直在我的应用程序中同时使用TabbarControllerNavigationController。当我尝试从导航堆栈(顶部项目)中获取它时,我得到了我的CustomNavigationController。但我需要查看 ViewController(可能是标签栏中的一个项目)。请你帮忙。提前致谢。

【问题讨论】:

  • 请发布您的代码
  • 你试试NSLog(@"%@", [self.window.rootViewController.navigationController.visibleViewController class]);

标签: ios iphone uinavigationcontroller uitabbarcontroller


【解决方案1】:

只需在 viewDidLoad 或 viewDidAppear 中为 tabBar 创建一个变量,然后在 appdelegate 中设置它。

您可以使用当前正在查看的 viewController 进行检查。

【讨论】:

    猜你喜欢
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2014-12-24
    • 1970-01-01
    • 2013-05-12
    • 2010-09-14
    相关资源
    最近更新 更多