UIAlertController does not appear at all

I am trying to add a UIAlertController to my application, but it does not appear at all. I tried the following:

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Message" message:@"Web Service is not available." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:ok]; [self presentViewController:alertController animated:YES completion:nil]; 

but it doesn’t appear at all, what am I doing wrong?

+8
ios objective-c uialertcontroller
source share
2 answers

In the controller of the initial presentation of the storyboard, this should be in viewDidAppear: Otherwise, if it is used in XIB, it will also display a warning in viewWillAppear and viewDidLoad .

I ran your code in the Single View application template on iOS 8 and 9, putting your code in this ViewController, in the following ViewController, :

  • viewDidAppear - failed
  • viewWillAppear - no warning is displayed; led to this conclusion in the console: Warning: trying to imagine whose view is not in the hierarchy of windows!
  • viewDidLoad - viewDidLoad is not displayed; led to this conclusion in the console: an attempt to load the view controller's view when it is released is not allowed and can lead to undefined () behavior.
+19
source share
 - (void)showMessage:(BOOL)animated { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Do not leave any Field Empty" message:nil preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self dismissViewControllerAnimated:YES completion:nil]; }]]; [self present:alertController animated:YES completion:nil]; 

}

where i call this method

  [self showMessage:YES]; 

It works great, someone can get benefits.

0
source share

All Articles