我正在显示顶视图控制器,并且我想显示警报控制器,但不显示。有什么办法吗?

var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)

最佳答案

( objective-c )

UIAlertController *alertVC = [UIAlertController
                                          alertControllerWithTitle:@"myTitle" message:@"myMessage"
                                          preferredStyle:UIAlertControllerStyleAlert];
[alertVC addAction:[UIAlertAction
                        actionWithTitle:@"Ok"
                        style:UIAlertActionStyleDefault
                        handler:^(UIAlertAction* action) {
                            [alertVC dismissViewControllerAnimated:YES completion:nil];
                        }
    ]];
[self presentViewController:alertVC animated:YES completion:nil];

09-07 11:56