jaggedcow
jaggedcow

Reputation: 1405

interactivePopGestureRecognizer popping too many views

I have two different UIViewControllers on the same UINavigationController. Both contain a tableview. If one of the cells on the first view controller is tapped, the second controller is pushed. If one of the cells in the second is pushed, another instance of the second controller is pushed.

When using the back button to go back, this all works perfectly. However, when using iOS 7's interactivePopGestureRecognizer, moving from one instance of the second view to another causes a crash.

I have statements logging the navigation controller activity and the gesture recognizer start.

This is the output when starting and then canceling the pop gesture:

Push <ViewController2: 0x15597f60>
Will show <ViewController2: 0x15597f60>
Did show <ViewController2: 0x15597f60>

Push <ViewController2: 0x15638b80>
Will show <ViewController2: 0x15638b80>
Did show <ViewController2: 0x15638b80>

Interactive pop started
Will show <ViewController2: 0x15597f60>

-navigationController:didShowViewController:animated: is never called. After this, attempting the gesture again will take you back to the first view controller (i.e. one pop too many), but the navigation bar will still display a back button and the title of the second view.

And then this is the output when attempting to pop normally:

Push <ViewController2: 0x15597f60>
Will show <ViewController2: 0x15597f60>
Did show <ViewController2: 0x15597f60>

Push <ViewController2: 0x15638b80>
Will show <ViewController2: 0x15638b80>
Did show <ViewController2: 0x15638b80>

Interactive pop started
Will show <ViewController2: 0x15597f60>
Unbalanced calls to begin/end appearance transitions for <ViewController1: 0x156e7050>.
Did show <ViewController1: 0x156e7050>

Any ideas as to why this is occurring?

Upvotes: 2

Views: 798

Answers (1)

ninjaneer
ninjaneer

Reputation: 7031

The problem is that the navbar is hidden. If you enable the navbar, the problem goes away. It's definitely a bug in Apple's implementation. Found the answer right when I put a bounty on it. Yikes.

See this for more information and a possible fix: https://stackoverflow.com/a/19834167/505259

UPDATE: Dennis' workaround did not work for me. One workaround I'm working on now is to NEVER TOUCH the interactivePopGestureRecognizer's delegate. Leave it alone. I suggest keeping the navigationBar alive but hidden (without using the hidden property, perhaps by hiding the subviews manually or by reordering the navigation bar layer to the back).

SECOND UPDATE: You can keep a reference to the current interactivePopGestureRecognizer's delegate (which is some private object you shouldn't touch). Then when you set the delegate to your own custom implementation, pass the delegate method calls back to the original private object. That should fix the problem entirely.

Upvotes: 2

Related Questions