How to get visible viewController from app delegate when using storyboard?

后端 未结 14 1704
小蘑菇
小蘑菇 2020-12-05 00:14

I have some viewControllers, and I don\'t use NavigationController. How can I get visible view controller in app delegate methods (e.g. appli

14条回答
  •  余生分开走
    2020-12-05 00:58

    If your app's root view controller is a UINavigationController than you can use this:

    UIViewController *currentControllerName = ((UINavigationController*)appDelegate.window.rootViewController).visibleViewController;
    

    and if you are using UITabBarController than you can use this:

    UIViewController *currentControllerName = ((UITabBarController*)appDelegate.window.rootViewController).selectedViewController;
    

提交回复
热议问题