-
-
Save ceekay1991/be467831f35b76a4bb61 to your computer and use it in GitHub Desktop.
iOS crash when presenting view controller after dialog display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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