1

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.

stalure
  • 21
  • 3

1 Answers1

1
  1. Make a "global" property in your application delegate that retains a reference to the root view controller, e.g. @property(nonatomic, retain) UIViewController *rootViewController

  2. 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

  3. 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)

  4. 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.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345