I have a UINavigationController onto which I push a 'loading screen' UIViewController whilst I asynchronously connect to a server. The push is implicitly animated with that sliding effect. If an error occurs whilst connecting, I pop the loading screen controller (again animated) and display an alert to the user.
All is good if I pop the view controller after the animation has completed, however if the animation has yet to complete odd things occur. Usually the loading screen view remains on screen even though it has been popped from the navigation controllers stack. I'm pretty sure the problem has to do with the animation being in progress. For example this contrived code snippet always leaves secondController's view on screen for me:
[navController pushViewController: secondController animated: YES];
[navController popToRootViewControllerAnimated: YES];
NSAssert([delegate.navigationController.viewControllers count] == 1, @"oops");
My current workaround is register a delegate with the navigation controller and implement the navigationController:didShowViewController:animated: method. I then only pop the loading screen controller when I know the first push animation has completed. However I would prefer to just end the animation early.
I have tried to call removeAllAnimations on all layers in the layer tree for all sub views of the navigation controller's view. Whilst this approach ended the animation early, it still often left the loading screen view still on display after it had been popped. So basically is there a correct way of ending an animation early, or should I just stick with my work around?