Search code examples
iphoneobjective-cuiimagepickercontroller

Presenting a modal view controller immediately after dismissing another


I'm dismissing a modal view controller and then immediately presenting another one, but the latter never happens. Here's the code:

 [self dismissModalViewControllerAnimated:YES];

 UIImagePickerController *picker = [[UIImagePickerController alloc] init];
 picker.delegate = self;
 picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
 [self presentModalViewController:picker animated:YES];

The first modal VC slides down, but the new picker never comes up. Any idea as to what's going on?


Solution

  • Like other animated things, dismissModalViewControllerAnimated doesn't block until the view controller disappears. Instead it "kicks off" dismissal of the view controller. You might need to use a callback in viewDidDisappear of modal controller 1 that calls something like modalViewControllerDisappeared in the parent view controller. In that method you present modal controller 2. Otherwise what Robot K said.