Reputation: 47911
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?
Upvotes: 7
Views: 14099
Reputation: 4323
From the console:
po [[[UIApplication sharedApplication] keyWindow] rootViewController]
<UINavigationController: 0x15f076c00>
Upvotes: 0
Reputation: 12717
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];
Upvotes: 17