Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show alert view in Swift (iOS8) with OK and Cancel button?

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.11k
    Comment on it

    To show an alert view in swift while using iOS8.

    Here is an example of how to use it:

    var MyAlert = UIAlertController(title: "Logout", message: "Are you sure?", preferredStyle: UIAlertControllerStyle.Alert)
    var MyOkayAction = UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default) {
    // Handle Okay logic here when user press Okay button, like
    action in self.performSegueWithIdentifer("storyboard_segue_identifier", sender:self)
    }
    var MyCancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default) {
    // Handle Cancel Logic here - when user press cancel button, like
    action in self.dismissViewControllerAnimated(true, completion: nil)
    }
    MyAlert.addAction(MyOkayAction)
    MyAlert.addAction(MyCancelAction)
    self.presentViewController(MyAlert, animated: true, completion: nil)
    

    Please note that if you are using iOS8, you should be using UIAlertController instead for UIAlertView is deprecated:

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: