Amos Amos - 4 months ago 9
Objective-C Question

Accessing a view controller created through Storyboard using the App Delegate

I'm working on an iOS5 app using storyboard, and I have a method in a view controller class that i'd like to access from the App Delegate. The trouble is, this view controller gets instantiated via a tab bar controller in storyboard, so the App Delegate has no direct way of calling the method I want...

For a view controller to get in touch with the App Delegate, all one has to do is use:

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

Is there a similarly easy way of pointing to an already-instantiated view controller or class?


You'll have to traverse the view hierarchy from the app delegate. Assuming the AppDelegate holds a reference to the UITabBarController, you could use the viewControllers property or selectedViewController property to get to your view controller.