Preliminary use of swift iOS development

Source: Internet
Author: User

Create a swift empty project with the Xcode6-Beta, create a UIViewController, and select swift language.

@ IBOutlet var titleLabel: UILabel? @ IBOutlet var button: UIButton? // @ IBOutlet weak var button: UIButton? /@ IBAction func btnClick (AnyObject ){}

 

Drag a UIButton and UILabel in the xib file to bind the object. The operation is similar to that in Xcode.

Add the content of the click event. In this example, a UIAlertView is displayed, and the delegate is self. The delegate statement is followed by a comma, as shown below,

class MainViewController: UIViewController,UIAlertViewDelegate{}

The initialization code for the current successful test of UIAlertView is as follows:

    let alert = UIAlertView()    alert.title = ""    alert.delegate = self    alert.message = "Hello Apple"    alert.addButtonWithTitle("OK")    alert.addButtonWithTitle("Cancel")    alert.show()

Other initialization APIs tried are executed abnormally.

//     let alert = UIAlertView(title: "title", message: "Hello Apple", delegate: self, cancelButtonTitle:"Cancel")//    let alert = UIAlertView(title: "title", message: "Hello Apple",delegate: self, cancelButtonTitle: "Cancel",otherButtonTitles:"OK");

Click the event delegate button to implement UIAlertView

    func alertView(alertView: UIAlertView!, clickedButtonAtIndex buttonIndex: Int)    {        switch buttonIndex        {        case 0:            println("alertView Ok!")        case 1:            println("alertView cancel!")        default:            println("alertView cancel!")        }    }

It can be seen that the switch does not require break, and the previous method cannot be used at present.

Case 0: case 1: println ("alertView cancel! ")
Break; // can be replaced with case 0 .. 2: println ("alertView OK! ")

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.