Getting Parent of A View Controller Pushed on a UINavigationController stack in a UITabBarController with Multiple UINavigationControllers?

Not sure if this is what you are looking for, but I think it is the top-most ViewController in nav viewControllers array.

Up vote 0 down vote favorite share g+ share fb share tw.

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?

Iphone objective-c ios foundation link|improve this question asked Sep 19 '11 at 13:58Ygam1,4181441 97% accept rate.

Even if you are able to achieve this using this method, this does not align well with the MVC design pattern. Ideally, your child VC should call a method of your model class (which may be a singleton) & the model class should notify your parent VC. You can do something like- //In your child VC MyModelClass sharedInstance buttonClickedInChildVC:@"propertyValue"; //In your Model class NSNotificationCenter defaultCenter postNotificationName:@"buttonClickedInChildVC" object:@"propertyValue"; //In your Parent VC NSNotificationCenter defaultCenter addObserver:self selector:@selector(buttonClickedInChildVC:) name:@"buttonClickedInChildVC" object:nil; -(void)buttonClickedInChildVC:(NSNotification *) notification { //do something } HTH, Akshay.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions