1
votes

I need to pass information between two view controllers I have. In the past, I have done this by importing my second view's .h into my first view's code, then implementing prepareForSegue in the first view and setting the values for the second view there. However, now my 2 view controllers are in a navigation controller, so there is no segue associated with the transition back to the root view controller (since it's done with [self.navigationController popToRootViewControllerAnimated:YES]).

Is there a method similar to prepareForSegue that I can use with a UINavigationController pop? Or do I have to set up either delegates or NSNotifications to send information back to the root view?

2
You should still have segues even if your are using a UINavigationController provided you are using a StoryboardgeminiCoder
I need to send the information from my second view back to the first, and that transition should be done with popToRootViewControllerAnimated, correct? And I don't have to set up a segue from the second view back to the first when it's done that way I don't think. I've edited my question to make it a little more clear that I need to go from second view back to first.GeneralMike

2 Answers

0
votes

A push segue is used to transition between one view controller and the next when they are in a UINavigationController. In your StoryBoard, drag from one view to the next and choose push as the segue type and set an identifier for the segue. Then you can setup up the destination view controller as normal.

To pass information back, you will need to set up a delegate since the pushed view controller should not have detailed info about who called it.

0
votes

You could try to implement your own

@interface MyUINavigationController : UINavigationController  <UINavigationBarDelegate>

Then implement:

- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item

and

-(BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item

You could then store variables in your UINavigationBar and use them as you wish by calling:

MyNavigationController *navi =self.navigationController;
navi.variable = myvariable;