So here’s a problem I’m really having trouble with. I am using this code to retrieve the parent controller of a UIViewController that is pushed to the UINavigationController stack:
MyAppDelegate *delegate = [[UIApplicationDelegate sharedApplication] delegate];
UINavigationController *nav = delegate.navigationController;
MyParentViewController *parent = (MyParentViewController *)nav.topViewController;
parent.myProperty = @"propertyValue";
However, this seems to only work when you are working with an application with a single navigation controller. My structure is:
->UITabBarController
-->UINavigationController
--->MyYetAnotherParentViewController
-->UINavigationController
--->MyOtherParentViewController
-->UINavigationController
--->MyParentViewController
which means that I have 3 navigation controllers inside the tab bar controller.
I am currently in the third navigation controller and have pushed a view controller above MyParentViewController.
I am trying to pass data from the UIViewController I pushed to MyParentViewController using properties. How will I retrieve the parent of the UIViewController I pushed to the stack if I have this setup?
Not sure if this is what you are looking for, but i think it is the top-most ViewController in [nav viewControllers] array.