I would like to present multiple modal views in sequence (e.g. show confirmation page after selecting a picture from image picker). My problem is that the animation of dismissal and presenting in subsequent steps without delay always crashes the app with an EXC_BAD_ACCESS
.
I assume that the problem is that CoreAnimation
does not distinguish between the two transitions and cannot detect properly whether the first one has ended or not.
My work around so far is to introduce a 1 section delay which seems to solve the problem. However, I think that this makes the code a bit fragile. Is there another workaround?
Is this a bug in UIKit and should I submit a bug report?
Sample code
Here is a simple case that reproduce the crash:
Create a new View-based project with the following class as the implementation of the main controller
Hit 'cancel' when image picker view is presented
Expected behavior: the picker view is dismissed and presented again due to the subsequent call in viewDidAppear
.
Actual behavior: It crashes with the stack trace presented below.
Code:
#import "SampleViewController.h"
@implementation SampleViewController
- (void)showModal {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[self presentModalViewController:picker animated:YES];
// [picker release];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self showModal]; // this line crashes the app
// the following works as desired
// [self performSelector:@selector(showModal) withObject:nil afterDelay:1];
}
@end
Crash Stack trace:
#0 0x30b43212 in -[UIWindowController transitionViewDidComplete:fromView:toView:] #1 0x3095828e in -[UITransitionView notifyDidCompleteTransition:] #2 0x3091af0d in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] #3 0x3091ad7c in -[UIViewAnimationState animationDidStop:finished:] #4 0x00b54331 in run_animation_callbacks #5 0x00b54109 in CA::timer_callback #6 0x302454a0 in CFRunLoopRunSpecific #7 0x30244628 in CFRunLoopRunInMode #8 0x32044c31 in GSEventRunModal #9 0x32044cf6 in GSEventRun #10 0x309021ee in UIApplicationMain #11 0x00002794 in main at main.m:14