views:

31

answers:

2

Okay, I understand how to work delegation in a modal view to send a message to the parentviewcontroller but what if I wanted to do that with 2 views that dont have that parent-child relationship?

I have a navigation controller that flips over a modal view and then that modal view pushes a new view controller. How do I let that pushed view controller talk to the navigation controller. The modal view code that I have been using places this in the parent:

-(IBAction)pressedUnitAddy {
UnitAddyView *unitVC = [[UnitAddyView alloc] init];

unitVC.delegate = self;

UINavigationController*  theNavController = [[UINavigationController alloc]initWithRootViewController:unitVC];

theNavController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:theNavController animated:YES];

[unitVC release];
[theNavController release];

}

-(void)didDismissUnitAddyView { [self dismissModalViewControllerAnimated:YES]; }

....and then I call the didDismissUnitAddyView from the UnitAddyView. Now, I am not trying to dismiss any views with what I am trying to do but I do want that pushed view controller to be able to speak to the navigation controller. How would I do that?

A: 

View controllers have a property, navigationController, that is nil if they're not pushed onto a navigation controller and is a pointer to the navigation if they are. Does that answer your question?

Seamus Campbell
The view controller i am talking about is being pushed onto a modal view. How do i make that view controller's nil navigationController point to some other navigation controller in the app. (not the modal view that pushed it.)
Rob
`navigationController` is a property solely for pointing to the navigation controller whose stack you're in, so you can't. However you could add another `UINavigationController*` property to your view controller and set the property when you create the view controller.What are you trying to do here exactly? It's hard to know if these suggestions are useful. It's unusual to need to know about a non-connected navigation controller and it suggests you're doing something strange.
Seamus Campbell
A: 

All I was trying to do was to reload the data on the nav controller screen. The UIViewController and the nav controller we not directly connected - they were separated through a modalview. All I did, and I should have thought of this earlier, was set the modal view's delegate to the nav controller and to call a method to reload the nav controller when the modal view is dismissed.

Rob