0
votes

I've got a tableview based navigation controller. The root view controller has a + button which adds a new item. This results in a push segue to the view controller which allows the user to enter the data for the new item.

On this view controller, the upper left navbar item is the standard labeled "back" button. I've placed a "Save" [bar] button [item] as the upper right navbar item.

I created an unwind IBAction pushed view controller.

I then control-dragged from the Save button to the exit on the view controller and wired it to the unwind IBAction.

This unwind action is getting called when I hit the Save button.

However, nothing I do in the unwind action pops the view controller. Here is a little code:

- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender     {

   return YES;
}

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {

   NSLog( @"Should seque from %@", identifier );
   return YES;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

}

- (IBAction)unwindFromGoalEdit:(UIStoryboardSegue *)segue {

   NSLog( @"UNWINDING!!");

   [self.navigationController popToViewController:segue.destinationViewController animated:YES];
}

In the unwind action below, I've attempted various ways to pop the view controller. But nothing happens. No runtime error, nothing. I do however see the NSLog() so I know it's being called.

Thoughts?

2

2 Answers

2
votes

The problem is probably that you have a retain cycle. The unwind automatically pops every view above it unless it can't. You do not pop anything from the unwind yourself. So, add a log to the view controller you're expecting to be popped in the dealloc method, or a break point. If that doesn't fire, then you know the view controller is not being popped. This almost certainly means you have a retain cycle. Look at your delegates or anywhere you are passing self (the parent) into a block. The top view controller should not have a strong reference to it's parent. Actually, no child should ever have a strong reference to its parent for this very reason. If it does the unwind will not work.

0
votes

Which class is unwindFromGoalEdit: in? It looks like you may have added it to the "new item" view controller... This method should be placed in the root view controller, and there is no need to call the popToViewController. An empty method should suffice here.