Friday, April 10, 2009

Hello World! Your Second iPhone Application!







So you think Tutorial #1 was easy? Well here comes #2.

First open up Xcode again and make a View Based application. Name it HelloWorld.

Look under your classes folder and click on HelloWorldViewController.h.


When making applications you'll have a .h and a .m file. In the .h you declare what you're going to do and in the .m you do it. So first in the HelloWorldViewController.h type this in...


What were doing here is creating two Interface Builder Outlets. One is a Text Field and were naming that Text Field nameField. Our second outlet is a Label and were naming that nameLabel. Under that we are retaining the properties so we can use them in our app.
The IBAction is an Interface Builder Action that when called upon will do what we tell it.


YOU MUST SAVE YOUR APP before continuing.

Click on HelloWorldViewController.xib to start making our interface.

Drag a label, text field, and round rect button onto your view and position them like this...


Next click on Tools >> Connections Inspector

Make sure the Files Owners is selected and


Connect the Text Field to nameField

Connect the Label to nameLabel

Connect the showName to the button and select touch up inside. We do this because our button will access the (IBAction)showName.

Like This...


When your done the connections inspector will look like this...


Now lets make our view look a little nicer. Double click the button and change the text to "Click Me". After that double click the label and change the text to "Please Enter Your Name". Also drag the ends of the label to the edge of the view. Like This...


While having the label selected go to Tools >> Attributes Inspector and make sure in the layout is selected as center.


Now, save up your Interface Builder and go back to Xcode.

Open up the HelloWorldViewController.m so we can enter in what the showName action will do.

Type in the following code




You must always synthesize what you previously stated in the HelloWorldViewController.h. In our case we have nameLabel and nameField.

Lastly we must define what showName will do. Type in this code...




This code is saying that the text of nameLabel is "Hey %@". %@ is the code for what is typed in the text field. Make sure you close this off with the curly brackets.

Your Done! Click Build & Go and play with your new app.


Stay Tuned to Make an App for more tutorials!





Thursday, April 9, 2009

Your First iPhone/iPod Touch Application...


Are you ready to make your first application? Well lets go!


First off I need you to start up Xcode. You will be using Xcode for all of your projects.

Next click on File and then New Project.



Make sure your in the iPhone OS templates and choose View Based Application. In later tutorials I will show you how to use others but for now View Based Application it is.


Name your new project MyApp and save it where ever you want.

Once you have Xcode opened up make sure the Active SDK is set to simulator and then hit Build & Go.




The iPhone Simulator should run and start your app. Doesn't look like much but don't worry we will get to that. Now go back into Xcode.

Since this is your first app I will make it easy and use no code. Instead open up MyAppViewController.xib located on the side under the resources folder.

Interface Builder is where you build your applications interface. Our interface will just be a label saying "My name is (your name here)". To do this click on Tools >> Library and look for the label.



Drag this Label on your View and position it how you like. Then rename it (by double clicking it) "My Name is (your name here)".


To make our app look really nice click on the background of the view and click up top on Tools >> Attributes Inspector. When Attributes inspector comes up click on background and change it to yellow.



Your almost done. Save Interface Builder and go back to Xcode. Hit that Build & Go button one more time. Yeah! Your first iPhone app. It should look something like this...



If you have any questions feel free to comment.

Stay Tuned beacuse the next tutorial is on its way. Tutorial #2 will allow you to type your name in a textfield then on the tap of a button a message will appear saying "Hey (your name here)".