My first Iphone App - XCode Tutorial

Create a new project in XCode

1. On left side under "iOS" select "Application"

2. Choose "View-based Application"

3. Click "Choose.."

4. Choose a project name e.g. "HelloWorld" and press "Save"

Open Interface Builder

1. In XCode, open folder "Ressources" under "Group & Files"

2. Double Click "MainWindow.xib" to open the Interface Builder

Overview of the Interface Builder

Once opened the Interface Builder you will see 4 windows:

-The library where you can find the UI Components

-The preview window

-The contents of the current XIB file

-The attributes window

Now lets create a simple view with a button and a label.

Create a view

Choose "View" from the library and drag'n'drop it on the preview window.

Create a button and a label

Choose both "label" and "Round Rect Button" from the library and drag'n'drop it on the view you just created.

Customize button and label

Double click the button and enter "Push" as text.

Double click the label and change the text to "Let's see" or
something else.

Save the interface

Choose "File" -> "Save" to save your interface.

Create a view controller

Rightclick "classes" under "Group & Files" and choose
"Add" -> "New File..."

Create UIViewController subclass

Choose "UIViewController subclass" and press next.

Enter "HelloWorldController.m" as filename.

HelloWorldController.h


#import <UIKit/UIKit.h>


@interface HelloWorldController : UIViewController {
    IBOutlet UILabel* label;
    IBOutlet UIButton* button;
}

-(IBAction)pressButton:(id)sender;

@end

HelloWorldController.m


#import "HelloWorldController.h"


@implementation HelloWorldController

-(IBAction)pressButton:(id)sender{
label.text = @"Hello World";
}

@end

Connect Controller to interface

In Interface Builder, drag and drop the HelloWorldController
to the content window of the interface.

Close the window that pops up.

Connect the UI Elements

Rightclick "HelloWorldController" and connect "view" with
the view in interface as shown on the image.

Do the same with the label and the button.

Finally connect the action "pressButton" with the touch
down event of the button.

Save the changes!

Build and Run!

Press "Build and Run" in XCode.

The simulator should open and show your application.

If you press the "Push" button the label should change
its text to "Hello World".

Congratulations to your first IPhone App!