First contact with the development of the Mac, found that the domestic relevant information is very poor, so write this article, as a study record. Mac App Development is also developed using OBJECTIVE-C, so it's not difficult to switch from iOS to Mac, and many things are the same.
This article takes a login interface as an exercise
All right, cut the crap.
First, the new project
Then select the project save path and click Create.
And then we can see an interface like this
Ii. Use of controls
Click the text box, Ctrl-Drag to the middle of @interface and @end, pop-up the Binding property box, enter the property name, and click Connect.
For a button, the type of connection should select action.
Then click on the top right corner to switch to a single editing interface
At this point, we have completed the creation of project projects and the binding of controls.
If you are familiar with iOS programming, you may be able to find a pattern here. Many of the user interface-related classes in Uikit are migrated from OSX AppKit. So, some of them just changed from the prefix NS in the Mac to the UI in iOS.
Third, the operation of the control
We can see in the viewcontroller.m file that there is a method named Loginbtn: This is the callback of the login button and we can do something about that method.
1 -(ibaction) LOGINBTN: (Nsbutton *) Sender {2 NSLog (@ "usernmae:%@ " , self.userName.stringValue); 3 NSLog (@ "password:%@", self.password.stringValue); 4 }
We enter the above code, and when you click the login button, the contents of the Username and password text boxes are output in the console.
Press Commend+r to run the program, enter the content in the text box, click Login, and the contents of the text box will be printed in the console.
This concludes the tutorial, where we only learned how to create engineering and bound controls and very few UI actions. If you are familiar with iOS programming, this tutorial may not be an egg for you ...
To continue learning about UI, you can continue to view UI-related articles.
Quick Start for Mac development