Hello! There is a button with a code that is triggered by touchUpInside. I would like to make a pop-up window (alertController), which requires confirmation of code execution (Yes - continue, No - cancel) contained in the button.

  • and what exactly does not work? - Max Mikheyenko
  • Put the code into a separate method and call this method by pressing YES - VAndrJ

1 answer 1

let alertController = UIAlertController(title: "Alert", message: "Are you okay?", preferredStyle: .Alert) // Initialize Actions let yesAction = UIAlertAction(title: "Yes", style: .Default) { (action) -> Void in println("The user is okay.") } let noAction = UIAlertAction(title: "No", style: .Default) { (action) -> Void in println("The user is not okay.") } // Add Actions alertController.addAction(yesAction) alertController.addAction(noAction) // Present Alert Controller self.presentViewController(alertController, animated: true, completion: nil) 

The answer is taken here .

  • Works! Thank! - Igor Zexyy