Issue: 1.5 (April/May 2003)
Author: Colin Cornaby
Author Bio: Colin Cornaby is an OS X developer. He is currently working on a new project, which will probably be out by the time you read this.
Article Description: No description available.
Article Length (in bytes): 4,939
Starting Page Number: 43
Article Number: 1523
Related Link(s): None
Excerpt of article text...
In the last column we built a program in Cocoa that displayed a sheet attached to a window. You learned to create a class to hold your code, how to add an outlet to your class, and how to create an action. This time we'll create a new project that will create variables in Cocoa, retrieve data from your interface, and practice sending data from your code back to the user.
First, you need to create a new Cocoa application project in Project Builder. For this exercise, you can name it anything you wish (although I named mine RBDExampleApp). Be careful about giving your application a name with a space in it. Project Builder has issues with projects that have spaces in their names.
You should then open your nib and lay out the window to look like the one in Figure 1. You will need to add two text boxes, and a button. After you have laid out the interface, create a new class. Name your new class "interfaceController", and add two outlets to it. Name one outlet "firstTextField" and the other outlet "secondTextField". Also add an action called "moveTheText". Create the files for your class, and then instantiate the class. Link the outlets up to the appropriate fields (firstTextField to the first text field, secondTextField to the second), and link the button to the action. Remember that it matters which direction the link is drawn. Refer back to the last column if you need to. When you are done, save the nib and close Interface Builder.
We'll cover new topics now. Everything in the last few steps was covered in the last column, but probably isn't terribly comfortable for you yet. Don't feel bad if you have to re-read the exercise we did last time with our sheet project. Trying to code Cocoa doesn't come naturally without a lot of experience. The more you code in Cocoa, the more you will become used to the way Cocoa works.
Now go back to Project Builder and take a look at your interfaceController.m file. As you recall from the last column, the .m file holds your code, while the .h file holds your definitions. You should see an empty method for "moveTheText" in the .m file.
Now it's time to add some code. Enter the following into the "moveTheText" method:
...End of Excerpt. Please purchase the magazine to read the full article.