I dislike doing “hello world!” tutorials, so instead I shall show you how to make a button! Buttons are more cool you see
First go and get the iPhone SDK(Software Development Kit) from developer.apple.com
If you are on a windows PC, I’m afraid that you can not do this tutorial. The iPhone SDK is limited to Mac OS X based computers.
In theory you have the iPhone SDK installed and ready, so go launch Xcode. This is the default IDE (integrated development environment).
Make a View based project and named it ‘button’

This is one of the building blocks Apple give you to start making your very own iPhone app! Cool eh?
So go ahead and double click buttonViewController.h (it’s in the folder named Classes) in the left pane. This is where we will tell the iPhone what is what
Add the following line (in bold below) into in the file
#import < uikit /UIKit.h >
@interface buttonViewController : UIViewController {
// this is a label control, static text. Has no interaction with the user
IBOutlet UILabel *myLabel;
}
@property (nonatomic, retain) UILabel *myLabel;
// our button control ![]()
- (IBAction)buttonPressed:(id)sender;
@end
Now the .h file or header file is edited we need to now edit the .m file, so go open buttonViewController.m. You shall see a load of green commented text. These are the most common methods you need in day to day iPhone development.
All the commented code can be deleted, you only need the following (as before, bolded text is the code added).
#import "buttonViewController.h"
@implementation buttonViewController
@synthesize myLabel;
-(IBAction)buttonPressed:(id)sender{
myLabel.text = @”moo”;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[myLabel release];
[super dealloc];
}
@end
Well that is it for the code, now the we go onto something called the Interface Builder. Find buttonViewController.xib in the folder Resources in the left pane of Xcode.
You shall see a grey rectangle

let’s add some stuff to it eh?
Open the library if its not open already (shift + cmd + L) and add a label and a button. You don’t have to do anything else, but to edit the text in the button and the label, simply double click them and enter the text you want to show when the app is launched

okay, now we need to hook up everything. Hold the control key on your keyboard and click on the “File’s Owner” file and drag to the label, and click “myLabel”.

This is where the File Owner object hides.
Now with the button, there is a variety of ways to hook it up. The way I find easier is to right click it and then click on Touch Up Inside (it’s near the botton of the pop-up) and drag that to the File Owner object. Then click on buttonPressed.
That is it, click on “Build and Run” in Xcode and your iPhone emulator will be launched with your application installed. Click the button and see the label’s text change.

If you have any questions, feel free to leave a comment





