Unexpected transition when dismissing multiple modal view controllers

Originator:Vytis
Number:rdar://18834972 Date Originated:31-Oct-2014 09:38 AM
Status:Duplicate of 18828778 (Open) Resolved:
Product:iOS SDK Product Version:8.1
Classification:Serious Bug Reproducible:Always
 
Summary:

The issue happens dismissing a modal view controller that itself has presented a modal controller. Before iOS8 both modal controllers would animate out together. With the current iOS version the top view controller disappears immediately after the start of the animation revealing the middle view controller which stays visible until the and of animation.

Steps to Reproduce:

1. Create an empty single view app project
2. Disable size classes in MainStoryboard
3. In the storyboard add three view controllers (Red, Green, Blue).
4. Make Red as the initial view controller in the storyboard.
5. Add this code to RedViewController.m:

- (void)viewDidAppear:(BOOL)animated
{
   [super viewDidAppear:animated];

   UIViewController *green = [self.storyboard instantiateViewControllerWithIdentifier:@"Green"];
   UIViewController *blue = [self.storyboard instantiateViewControllerWithIdentifier:@"Blue"];
   [self presentViewController:green animated:NO completion:NULL];
   [green presentViewController:blue animated:NO completion:NULL];
}

6. Add a button in Blue view controller and wire it to this method:

- (IBAction)dismissTapped:(id)sender
{
   UIViewController *parent = self.presentingViewController;
   [parent.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
}

7. Launch the app and tap “Dismiss” button on Blue controller.

Expected Results:

Blue controller would animate out revealing Red controller.

Actual Results:

At the start of the animation Blue controller disappears instantly revealing Green controller which then continues to animate out revealing Red controller. It is easier to see this effect in the video provided.

Regression:

Problem is only present on iOS 8.0 and above

Notes:

This behavior seem to contradict the documentation. This is what is written about dismissViewControllerAnimated:completion:

"If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.”

Comments

Had the same issue, created sample app and GIFs file.

https://github.com/bsuvorov/ios_bug_demos#ios8-modal-dismiss-bug-apple-radar-20167513

Submitted Radar 20167513


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!