小编Shi*_*rra的帖子

显示来自viewDidLoad的警报消息

我想从一个显示警报消息viewDidLoad()的方法,ViewController.m从替代viewDidAppear()方法.

这是我的代码:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

警告:试图提出<UIAlertController: 0x7fbc58448960><ViewController: 0x7fbc585a09d0>他们的看法是不是在窗口层次!

xcode objective-c uialertview ios

13
推荐指数
2
解决办法
8714
查看次数

标签 统计

ios ×1

objective-c ×1

uialertview ×1

xcode ×1