An attempt to present a UIAlertController on a UIViewController whose view is not in the window hierarchy

I am trying to test the UIAlertController in iOS 9 for my sample application, and during its launch I found a warning in the console. I am using Xcode 7 and Objective C.

Please find the following warning message in the console.

Warning: attempt to present <UIAlertController: 0x7fb1bb5be040> on <ViewController: 0x7fb1bb5aef30> whose view is not in the Hierarchy window!

See below for more information.

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"This is an alert." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}]; [alert addAction:defaultAction]; [self presentViewController:alert animated:YES completion:nil]; 
+5
source share
1 answer

I assume that you are trying to submit a warning to view the boot. You will receive an error message:

Warning: attempt to present <UIAlertController: 0x7fb1bb5be040> on <ViewController: 0x7fb1bb5aef30> whose view is not in the Hierarchy window!

because, given the load, the views are not yet available for display to the user. Therefore, you cannot submit a warning. Move the code to viewDidAppear

+14
source

Source: https://habr.com/ru/post/1233244/


All Articles