The next step is to begin designing the classes required by the application. Because cocoa uses an object-oriented programmer
Type 56. After the class is created, append the program code to it.
6.3.1 create a class file
First, create a class. Select the classes directory on the left of the Project window, and select File> New file to open the file creation window, as shown in Figure 6.5. Select cocoa class> Objective-C class in Mac OS X, and click Next.
In the attribute settings window shown in Figure 6.6, set the class file name to appcontroller and click Finish. The new class appcontroller is created successfully. The new appcontroller. h and appcontroller. M files are displayed in the classes directory on the left of the Project window, as shown in Figure 6.7.
6.3.2 append code
In the next step, edit the generated header file appcontroller. H (a file suffixed with. H is usually called a header file, and a file suffixed with. m is called the main document in this book) to append some necessary code.
First, open appcontroller. h In the project window. We have noticed that some code has been found in the appcontroller. h file. These code are some class definitions generated by the template, and the content is still blank. Add an instance variable and a method. These are all required for displaying the graphic user interface.
Append the following two lines of code to the header file appcontroller. h. The Shadow part is the newly appended two-line generation.
.
1 # import <Cocoa/cocoa. h>
2
3 @ interface appcontroller: nsobject
4th {
65 iboutlet ID textfield;
Chapter
6}
587-(ibaction) sayhello :( ID) sender;
8 @ end
After editing, save all content. Append the instance variable named textfield and the method named sayhello: to the class.
However, have you noticed that the iboutlet string is added at the beginning of the textfield instance variable
Sayhello: The ibaction string is appended to the method.
In fact, the result is that the append instance variable is changed to an "outlet", and the append method is changed to an "action ). These will be used in the use of interface builder for user interface timing. So what are "Sockets" and "actions? In a word, the socket is the append part interface in interface builder, and the action is to receive the notification when the user clicks the button. There will be a special chapter (chapter 1) to introduce the use of sockets and actions in detail.
The last step of this step is to save all the files. Do not underestimate this save action. When converting between xcode and interface builder, it is easy to forget to save it in time, as a result, the cause of the error cannot be found for half a day.
This article is excerpted from the book "software rich password: iPhone application development strategy-a simple introduction to objective-C 20.
The book "software rich password: An in-depth introduction to iPhone application development strategy objective-C 20" has been officially published by the Electronics Industry Publishing House and edited by Wang Zhigang.
Purchase address:
Dangdang:
Http://product.dangdang.com/product.aspx? Product_id = 21099098 & ref = search-1-Pub
Zhuo yuewang:
Http://www.amazon.cn/%E8%BD%AF%E4%BB%B6%E5%88%9B%E5%AF%8C%E5%AF%86%E7%A0%81-iPhone%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5%E4%B9%8B%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BAObjective-C-2-0-%E7%8E%8B%E5%BF%97%E5%88%9A/dp/B005468TFI/ref=sr_1_1? Ie = utf8 & qid = 1307935193 & sr = 8-1
China Interactive publishing network:
Http://product.china-pub.com/193976