1

我正在尝试将 Ok 按钮添加到 UI 警报,但我无法使用 alertController.addAction 添加它

在这种情况下我该怎么办?

提前致谢!!

if error == nil {
                let alert: UIAlertController = UIAlertController(title: "Account Created", message: "Please confirm your email", preferredStyle: .Alert)

                let okButton = UIAlertAction(title: "Ok", style: .Default) { action -> Void in
                    self.performSegueWithIdentifier("toMain", sender: self)

                    alertController.addAction(okButton)


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

                }

                } else {

                println("\(error)")
            }
4

1 回答 1

1
  1. alert代替alertController
  2. alert.addAction应该在你的okbutton行动之外。

更改您的代码:

if error == nil {
    let alert: UIAlertController = UIAlertController(title: "Account Created", message: "Please confirm your email", preferredStyle: .Alert)

    let okButton = UIAlertAction(title: "Ok", style: .Default) { action -> Void in
        self.performSegueWithIdentifier("toMain", sender: self)

    }
    alert.addAction(okButton)

    self.presentViewController(alert, animated: true, completion: nil)
 } else {

            println("\(error)")
        }
于 2015-07-21T05:41:04.053 回答