Skip to content

Instantly share code, notes, and snippets.

@jonklein
Created September 22, 2014 19:08
Show Gist options
  • Save jonklein/b85b7835d4dc615a9593 to your computer and use it in GitHub Desktop.
Save jonklein/b85b7835d4dc615a9593 to your computer and use it in GitHub Desktop.
iOS crash when presenting view controller after dialog display
// the fact that alertView is retained here seems important -- does not reproduce otherwise.
self.alertView = [[UIAlertView alloc] initWithTitle: @"OK" message: @"OK" delegate: nil cancelButtonTitle: @"Cancel" otherButtonTitles: nil];
[self.alertView show];
// White the dialog is open, present a modal view controller. In a real-world scenario, this is actually
// occurring when the view controller is presented in response to alertView:clickedButtonAtIndex:, but
// for this example, we'll do it automatically.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
UIViewController *controller = [[UIViewController alloc] initWithNibName: nil bundle: nil];
controller.view = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)];
controller.view.backgroundColor = [UIColor greenColor];
[self.root presentViewController: controller animated: YES completion: nil];
});
// Dismiss the alert via simulating a button click.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.alertView dismissWithClickedButtonIndex: 1 animated:YES];
});
// Dismiss the view controller.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.window.rootViewController dismissViewControllerAnimated: YES completion: nil];
});
// Set the status bar to hidden and a crash results.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setStatusBarHidden: YES];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment