How To Display An Alarm Persuasion Amongst Swift

Display an Alert View alongside Swift

First we'll practise a constant of UIAlertController. Since we'll live using an alert, the UIAlertControllerStyle is develop to default. It tin bring other values such every mo ActionSheet, Alert, together with RawValue.

 let alertPrompt = UIAlertController(title: "Simple Alert View", message: "Hello, World", preferredStyle: UIAlertControllerStyle.Alert)

Next, we'll live adding a push within the newly created alertcontroller. We'll develop the handler to aught since nosotros don't withdraw whatever activeness yet. But yous may telephone weep upwards a business office when a push is click yesteryear setting the handler to about function. 
Note: The handler business office must bring a parameter of UIAlertAction type (e.g. func buttonHandler(alertView: UIAlertAction){})

alertPrompt.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:nil))
            
And lastly inwards club to present the warning view, yous must acquaint it yesteryear the calling the presentViewController method.


presentViewController(alertPrompt, animated: true, completion: nil)

Summary of Code:

Inside an activeness function, house the next trouble of codes.

let alertPrompt = UIAlertController(title: "Simple Alert View", message: "Hello, World", preferredStyle: UIAlertControllerStyle.Alert)

alertPrompt.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:nil))
            

presentViewController(alertPrompt, animated: true, completion: nil)

or to lead maintain a push click inwards the warning view, nosotros tin have

let alertPrompt = UIAlertController(title: "Simple Alert View", message: "Hello, World", preferredStyle: UIAlertControllerStyle.Alert)

alertPrompt.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:"btn_clicked"))
            

presentViewController(alertPrompt, animated: true, completion: nil)

Then nosotros tin declare the push handle:

func btn_clicked(alertView: UIAlertAction!){
        presentViewController(imagePicker, animated: true, completion: nil)
 println("Ok")
 }

Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.