0

I have a View Controller that has a custom push transition when a table cell is tapped and performs the standard pop transition when the back bar button item is tapped. The problem is when I try to go to the same view controller from the previous controller, the app crashes. Below is the UINavigationControllerDelegatefunction I'm implementing:

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
    return (operation == UINavigationControllerOperationPush ? animator : nil);
}

Any clue is appreciated!

Thanks in advance.

pedroremedios
  • 763
  • 1
  • 11
  • 39
  • 1
    How does your app crash? Which line? Stacktrace? Message? – Hermann Klecker Jul 06 '14 at 19:16
  • It crashes at int main. No message and I don't know what stacktrace to show. – pedroremedios Jul 06 '14 at 20:18
  • I think it crashes at `- [UINavigationController _customTransitionController:]`. It's before `objc_msgSend` – pedroremedios Jul 06 '14 at 20:32
  • 2
    You need to set your navigation controller's delegate back to nil or some other delegate after performing your custom transition. This puts the pop animation back to its standard, and if you return to the tableview's controller, you should ask to be its delegate again. If that tableview controller also as a pop, then you also need to let go of the nav controller's delegate before poping, because that is also calling your custom delegate. – Afonso Tsukamoto Jul 06 '14 at 20:38
  • That worked thanks!! If you can just put what you wrote as an answer so I can mark it as the accepted answer please :) – pedroremedios Jul 06 '14 at 20:45
  • 1
    I put self.navigationController.delegate = nil; in willMoveToParentViewController and that fixed it for me. I had same crash at UINavigationController customTransitionController. – Doug Voss Oct 30 '15 at 00:24

1 Answers1

7

I had a problem, where the NavigationController's delegate was set to a view controller that had been deallocated, which caused a crash in [UINavigationController _customTransitionController:].

Especially when using unwind segues, it does NOT seem that any intermediate view controllers receive a viewWillDisappear callback before getting deallocated. The remedy here is to implement the following in the destination unwind view controller:

-(IBAction)unwindSegue:(UIStoryboardSegue*)segue{
    self.navigationController.delegate = nil;
}
hlynbech
  • 662
  • 4
  • 13