UIAlertController标题和消息没有出现

时间:2016-06-03 18:50:37

标签: ios swift

我正在使用此代码:

let alertController = UIAlertController(title: "Default AlertController", message: "A standard alert", preferredStyle: .Alert)

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action:UIAlertAction!) in
    print("you have pressed the Cancel button");
}
alertController.addAction(cancelAction)

let OKAction = UIAlertAction(title: "OK", style: .Default) { (action:UIAlertAction!) in
    print("you have pressed OK button");
}
alertController.addAction(OKAction)

self.presentViewController(alertController, animated: true, completion:nil)

这就是它的样子:

enter image description here

以下是演示文稿的代码。我正在检查CloudKit的auth状态,然后在出现错误时显示警告:

dispatch_async(dispatch_get_main_queue(), {
    self.activityIndicator.stopAnimating()

    guard let user = user where succeeded && error == nil else {
        if let error = error {
            switch error {
            default:

                let alertController = UIAlertController(title: "Default AlertController", message: "A standard alert", preferredStyle: .Alert)

                let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action:UIAlertAction!) in
                    print("you have pressed the Cancel button");
                }
                alertController.addAction(cancelAction)

                let OKAction = UIAlertAction(title: "OK", style: .Default) { (action:UIAlertAction!) in
                    print("you have pressed OK button");
                }
                alertController.addAction(OKAction)

                self.presentViewController(alertController, animated: true, completion:nil)
            }
        }
        return
    }
})

0 个答案:

没有答案