IOS 8: UINavigationController appears with no animation and then click

There are many places in our application that we need to quickly call 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 great and the animation showed the new view controller sliding over the current one as the navigation controller was first rendered without animation.

Now with iOS8 this seems to have changed, and now what happens is the top-level controller is popped and the main view controller blinks for a split second and then the new view controller is pushed. I created an Xcode project from scratch for iOS8 and tried to test this. Please see this GIF for a demo of what it looks like. Every time we click one of the buttons on the main side of the split view, we execute the above two lines of code on the partial (right) side of the split. Note that the gray view (which is the root of the navigation controller) flashes for a short second before a new one is pressed.

I tried to find the reason why this might have changed in iOS8, but I didn't seem to find any documentation on it. Anyone have any ideas on what might have caused this change? Any input would be greatly appreciated!

Also, I tried to play around with the code and found myself executing the following code instead

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

      

seems to fix the problem. However, I would rather not use this if possible, because there are many places in our application that do this two-line pop-push combination and I would rather not change it all over the place.

Thank!

+3


source to share


1 answer


I came up with similar solutions for you, but this is the situation first.

First, you can override the back buttons on the stack you manipulate to navigate to the root (or whatever controller you want to be root).

Second, you can add a category to the UINavigationController by basically implementing the above code. This saves you the trouble of changing it everywhere in your application.



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

      

I am planning to implement the latter, unless Apple fixes / responds.

+1


source







All Articles