如何在UIAlert

时间:2015-09-12 05:29:31

标签: swift uialertview

我试着简单地调用一个名为“GoToNewShoot”的函数当用户按下“确定”按钮时,警告弹出谢谢!。

代码:

   @IBAction func GobacktoCamera(sender: AnyObject) {
    var alertController = UIAlertController(title: "Just Checking", message: "Are You Sure You Want to Start over ", preferredStyle: UIAlertControllerStyle.Alert)
    alertController.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Cancel, handler: nil))
    self.presentViewController(alertController, animated: true, completion: nil)

2 个答案:

答案 0 :(得分:21)

你可以通过这种方式使用addAction处理程序来实现:

@IBAction func GobacktoCamera(sender: AnyObject) {

    var alertController = UIAlertController(title: "Just Checking", message: "Are You Sure You Want to Start over", preferredStyle: UIAlertControllerStyle.Alert)

    alertController.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { action in
        //run your function here
        self.GoToNewShoot()
    }))

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


func GoToNewShoot(){

    println("Method Called")
}

答案 1 :(得分:0)

CREATE TABLE Item
(
    ID INT auto_increment,
    ItemCode VARCHAR(10) unique NOT NULL,
    ItemDescription VARCHAR(50),
    Price DECIMAL(4,2) DEFAULT 0,

    PRIMARY KEY(ID)
);