How to Display an Alert View with Swift
Tech-Today

How to Display an Alert View with Swift


Display an Alert View with Swift

First we'll create a constant of UIAlertController. Since we'll be using an alert, the UIAlertControllerStyle is set to default. It can have other values such as ActionSheet, Alert, and RawValue.

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

Next, we'll be adding a button inside the newly created alertcontroller. We'll set the handler to nil since we don't need any action yet. But you may call a function when a button is click by setting the handler to some function. 
Note: The handler function must have a parameter of UIAlertAction type (e.g. func buttonHandler(alertView: UIAlertAction){})

alertPrompt.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:nil))
            
And lastly in order to show the alert view, you must present it by the calling the presentViewController method.


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

Summary of Code:

Inside an action function, place the following line 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 handle a button click in the alert view, we can 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 we can declare the button handle:

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





-
Send Email using MFMailComposer (Template)1.) Import MessageUI      import MessageUI 2.) Show Email func showMail() { let mailComposeViewController = configuredMailComposeViewController() if MFMailComposeViewController.canSendMail()...

- Dns That You Could Choose From In The Philippines
Below are the DNS I'm using in the Philippines. The last is specifically for Globe network. OpenDNS - fast but restrictive    208.67.222.222    208.67.220.220 Cisco - ok for me    64.102.255.44    128.107.241.185...

- How To Access Asp:textbox With Runat=server Attribute In Javascript
For example you have a textbox which has a default value, and you want to clear that value when the user click on the textbox: <asp:TextBox ID="txtBox" runat="server" onclick="clear()" Text="Enter Keyword" /> <script type="text/javascript">...

- Create A New Eclipse-rcp Preference Page By Code When A Listener Is Invoked
Objective: -To create an eclipse-rcp preference page without using the preference extension, all is done in code. This is done by creating a customized button with a SelectionListener, and eventually that action will call a customized preference page....

- Remove Or Customize The Close/minimize/maximize Button In An Eclipse-rcp's Application's Window
There are times when you just want your eclipse rcp in the middle of the screen. To do that you have to set the style bits for the window's shell to customize the look of your window. The API is accessible here: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/index.html,...



Tech-Today








.