如果这样在一个普通的viewcontroller里面写的话,会报错误
whose view is not in the window hierarchy!
viewDidLoad
viewDidAppear:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"aaa" message:@"ddddd" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];UIAlertAction *certainAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];[alertController addAction:cancelAction];[alertController addAction:certainAction];
self.alterVC = alertController;
// [self performSelector:@selector(delayMethod) withObject:nil afterDelay:1.0f];
[self presentViewController:alertController animated:YES completion:nil];
需要这样写:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"aaa" message:@"ddddd" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];UIAlertAction *certainAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];[alertController addAction:cancelAction];[alertController addAction:certainAction];
self.alterVC = alertController;
// [self performSelector:@selector(delayMethod) withObject:nil afterDelay:1.0f];
[self presentViewController:alertController animated:YES completion:nil];