MAC OS development from getting started to crashing (i)

Source: Internet
Author: User

Objective of this article: Create a Mac app from Xcode. Click the button to pop up the Hello World window with the following effect.

There are 4 steps we can take to achieve the above effect.

1. Create a Mac App project.

2. Layout "button" control

3. Establish the appropriate "connection"

4. Write the popup code.

First, create a Mac app project

1. Open Xcode and select Create a new Xcode project.

2. Find the Mac OS option and select the Cocoa App

3. Fill in the relevant information.

4. Select the folder and click Create.

At this point, we run the project by Command + R, and find that there is only one empty window at this time.

So, we'll move the button layout to the form next.

Ii. Create, Layout, and button controls

1. Double-click Main.storyboard.

2. Locate the button control in the lower left corner

3. Drag the push button control to the area, double-click the button, modify the button name to click Me

Continue command + R to run, if no surprises, there is a click me button in the form now, but now the button is just a decoration, we need to connect it with the popup code.

Third, establish the corresponding connection

1. In the navigation bar, click Main.storyboard, and then locate and click ViewController.h, as shown in.

2. In the left-hand navigator panel, double-click Main.storyboard to pop up the new Main.storyboard window.

3. Right-click me under the Sent action list, click Action, and then drag a location between the two lines of @interface and @end in the ViewController.h file, then enter name to generate the following code.

D. Write the code of the popup window.

1. Double-click the viewcontroller.m file to locate the function in.

2. Write the following code.

    Define the alert variable    nsalert *alert = [[Nsalert alloc]init];    Add OK button    [alert addbuttonwithtitle:@ "OK"];    Pop-up window content    Alert.messagetext = @ "Hello world!";    Descriptive text    Alert.informativetext = @ "This is my first MAC app.";    [Alert Beginsheetmodalforwindow:[self.view window] completionhandler:^ (nsmodalresponse returncode) {        if (ReturnCode = = Nsalertfirstbuttonreturn) {            NSLog (@ "This is OK Button tap");        }    ];

Complete!

MAC OS development from getting started to crashing (i)

Related Article

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.