baselq
baselq

Reputation: 301

iOS 8: UINavigationController popping without animation and then pushing

In our app, there are many places that we need to quickly pop a view controller without animation and then push a new one with animation. We would do something like

[navController popViewControllerAnimated:NO];
[navController pushViewController:newVC animated:YES];

Pre-iOS8, this worked fine and the animation showed the new view controller sliding in over the current one, since the navigation controller was first popped without animation.

Now with iOS8, this seems to have changed and what happens now is the top view controller gets popped and the underlying view controller flashes for a split second and then the new view controller gets pushed on. I created a Xcode Project from scratch for iOS8 and tried to test this. Please see this GIF for a demonstration of what it looks like. Every time we tap one of the buttons in the master side of the split view, we perform the above two lines of code on the detail (right) side of the split. Note that the gray view (which is the root of the navigation controller) flashes for a brief second before the new one is pushed.

I have tried searching for any reason why this might have changed in iOS8 but I cant seem to find any documentation on it. Any one have any ideas on what might have caused this change? Any input would be greatly appreciated!

Also, I tried playing around with the code and discovered that doing the following code instead

NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:navController.viewControllers];
[viewControllers removeLastObject];
[viewControllers addObject:newVC];
[navController setViewControllers:viewControllers animated:YES];

seems to fix the issue. However, I would prefer not to use this if possible since there are many places in our app that do this 2-line pop-push combo and I would prefer not to have to change it all over the place.

Thank you!

Upvotes: 3

Views: 2408

Answers (1)

ender44
ender44

Reputation: 31

I came up with similar solutions to you, the first is situational however.

First, you could override the back buttons in the stack you're manipulating to pop to root (or whatever controller you want to be root).

Second, you could add a category to UINavigationController basically implementing the code you listed above. That would save you from having to change it everywhere in your app.

-(UIViewController *)popPushViewController:(UIViewController *)controller animated:(BOOL)animated {
    NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.viewControllers];
    [viewControllers removeLastObject];
    [viewControllers addObject:controller];
    [self setViewControllers:viewControllers animated:animated];
}

I'm planning on implementing the latter if Apple doesn't fix it/respond.

Upvotes: 1

Related Questions