创建弹出对话框警报

时间:2015-02-28 19:56:33

标签: swift

我正在尝试创建一个popup uialert类型来创建一个确认框。我在ViewControllerTwo中有一个按钮,当按下导航回ViewControllerOne时,我想创建一个弹出消息,要求确认(是或否)我是否真的要导航到ViewControllerOne。如果是,则返回ViewOne,如果没有它停留在ViewTwo上。我该怎么做?

1 个答案:

答案 0 :(得分:1)

@IBAction func showAlertTapped(sender: AnyObject) {
        //Create the AlertController
        let myAlertController: UIAlertController = UIAlertController(title: "Hey..!", message: "Are You sure to Do some stuff??", preferredStyle: .Alert)

        //Create and add the Cancel action
        let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
            //Do some stuff
        }
        myAlertController.addAction(cancelAction)
        //Create and an option action
        let nextAction: UIAlertAction = UIAlertAction(title: "Next", style: .Default) { action -> Void in


       let mainStoryboard = UIStoryboard(name: "Storyboard", bundle: NSBundle.mainBundle())
       let vc : UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("vcMainLogin") as UIViewController
       self.presentViewController(vc, animated: true, completion: nil)
        }
        myAlertController.addAction(nextAction)


        //Present the AlertController
        self.presentViewController(myAlertController, animated: true, completion: nil)
    }