Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy UIAlertView prevents my modal view controller from being displayed?
    text
    copied!<p>Let's say that when the user presses a button a message needs to be shown and then a modal view controller is displayed. I would write something like that :</p> <pre><code>- (void)pickImageButtonPressed:(id)button { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Some alert" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [[UIApplication sharedApplication].keyWindow.rootViewController presentModalViewController:picker animated:YES]; [picker release]; } </code></pre> <p>With this code, <strong>the modal view controller is simply not displayed</strong> !</p> <p>However, if I <strong>switch the two blocks</strong> of code (show modal first, then show the alert), the view controller is displayed modally and the alert shows up above it, exactly as I want.</p> <p>My question is: <strong>why the alert prevents the modal view controller from being displayed ?</strong></p> <p>Please note that I do not want to wait for alert to be dismissed before calling <em>presentModalViewController</em>.</p> <hr> <p><strong>Update :</strong> I figured out that my production code was a bit more complicated than what I first put. I updated the example code and then finally found a simple example to reproduce the problem.</p> <p>Note that in my production code, the popup is displayed from a place where I don't have any reference to a view controller, that's why I use <em>[UIApplication sharedApplication].keyWindow.rootViewController instead of a direct reference to a view controller</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload