I have a menu table in the root view of a storyboard that I want reloaded whenever a sub view updates data. How do I get a reference to the root view so that I can call the reloaddata method on it?
First, you register the storyboard with the AppDelegate by passing in the storyboard's name, MainStoryboard. Next, you tell the application to instantiate an initial view controller from the storyboard by calling InstantiateInitialViewController on the storyboard, and you set that view controller as the application's root view controller.
But it's easy to do. The root view controller is simply the view controller that sits at the bottom of the navigation stack. You can access the navigation controller's array of view controllers through its viewControllers property. To access the root view controller, we ask for the first item of the array of view controllers.
In Xcode, open the Library (via View > Show Library or Shift + Command + L) to show a list of objects that can be added to the Storyboard. Add a Navigation Controller to the Storyboard by dragging the object from the list onto the Storyboard. By default, the Navigation Controller will provide two screens.
The content of a storyboard is stored as an XML file. At build time, any .storyboard files are compiled into binary files known as nibs. At run time, these nibs are initialized and instantiated to create new views. A Segue, or Segue Object, is used in iOS development to represent a transition between scenes.
You can access it using the below code if the rootViewController
is a UIViewController
UIViewController *rootController=(UIViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
But if it's a UINavigationController
you can use the code below.
UINavigationController *nav=(UINavigationController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
UIViewController *rootController=(UIViewController *)[nav.viewControllers objectAtIndex:0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With