title: Display Alert Message from viewDidLoad
body: <p>I want to display a alert message from <code>viewDidLoad()</code> method of <code>ViewController.m</code> instead from <code>viewDidAppear()</code> method.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>- (void)viewDidLoad {
      [super viewDidLoad];
  
      //A SIMPLE ALERT DIALOG
      UIAlertController *alert =   [UIAlertController
                                alertControllerWithTitle:@"My Title"
                                message:@"Enter User Credentials"
                                preferredStyle:UIAlertControllerStyleAlert];
  
  
      UIAlertAction *cancelAction = [UIAlertAction
                                 actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
                                 style:UIAlertActionStyleCancel
                                 handler:^(UIAlertAction *action)
                                 {
                                     NSLog(@"Cancel action");
                                 }];
  
      UIAlertAction *okAction = [UIAlertAction
                             actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction *action)
                             {
                                 NSLog(@"OK action");
                             }];
  
      [alert addAction:cancelAction];
      [alert addAction:okAction];
      [self presentViewController:alert animated:YES completion:nil];
  }
  </code></pre>
  
  <p>and I am getting this error: </p>
  
  <blockquote>
    <p>Warning: Attempt to present <code>&lt;UIAlertController: 0x7fbc58448960&gt;</code> on <code>&lt;ViewController: 0x7fbc585a09d0&gt;</code> whose view is not in the window hierarchy!</p>
  </blockquote>