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)