Chcę wyświetlić komunikat alertu z metody viewDidLoad()
z ViewController.m
zamiast z metody viewDidAppear()
.Wyświetl komunikat alertu z viewDidLoad
Oto mój kod:
- (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];
}
i otrzymuję ten błąd:
Warning: Attempt to present
<UIAlertController: 0x7fbc58448960>
on<ViewController: 0x7fbc585a09d0>
whose view is not in the window hierarchy!
Prawdopodobny duplikat [którego widok nie znajduje się w hierarchii okna] (http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy) – Woodstock
@Woodstock moje pytanie jest inny ... –