Search code examples
iosuiviewcontrolleruitabbarcontrolleruiapplicationdelegate

iOS - Get current view controller


In my application my initial view controller pushes a UITabBarController modally which has 4 tabs, I want to get form the AppDelegate one of the controllers in one of the tabs, but I'm not sure how to do so.

I need this to be able to handle a URL callback using

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

Solution

  • So you are trying to grab one of the view controllers out of the tabbarcontroller?

    UIViewController *myController = [[tabBarController viewControllers] objectAtIndex:0];
    

    0 is the tab index. To use this method you'll need to know what index the tab you want is at.