I apologize if this is an easy one.
I have my root view controller NB_ViewController. I have another class named ShowScreen. How can ShowScreen access a method in NB_ViewController?
Thank you so much in advance.
Make a "global" property in your application delegate that retains a reference to the root view controller, e.g. @property(nonatomic, retain) UIViewController *rootViewController
When you instantiate the root view controller in the app delegate's -applicationDidFinishLaunching:
method, set the self.rootViewController
property equal to the newly instantiated view controller
Add a #define
macro in your constants file (or in the class header where you want to use it) that lets you access the application delegate from anywhere, e.g. #define UIAppDelegate ((MyAppDelegate *)[UIApplication sharedApplication].delegate)
In ShowScreen
, call a property or method of the root view controller through the app delegate, e.g. [[UIAppDelegate rootViewController] someRootVCProperty]
or [[UIAppDelegate rootViewController] someRootVCMethod:foo withArgument:bar]
Step 2 should be optional if you use Interface Builder and the corresponding root view controller IBOutlet
is called rootViewController
.