Tuesday, 3 January 2012

How To Creating a Simple basic iPad application Step 1


Due to the recent announcement of the iPad more people are interested to learn how to develop for the iPhone OS. This tutorial will be a basic learning tutorial for beginners who want to start developing iPad applications.The application that we will be creating will consist of two button and one label.

Create a new project

First of all open Xcode and click "Create a new Xcode project". Select View-based Application and then iPad as the product.


Save the project as Tutorial.

Outlets and Actions

For things such as labels and textfields we use IBOutlets and for buttons we use IBActions. IB stands for Interface Builder and is what we will use to create our interface and link the connections.
To add our outlets and actions open up TutorialViewController.h.
Under @interface TutorialViewController : UIViewController { add:
IBOutlet UILabel *currentNumber;
Then before @end add:
-(IBAction)incrementNumber:(id)sender;
-(IBAction)decrementNumber:(id)sender;
Save TutorialViewController.h.

Create the interface and make connections

Open up TutorialViewController.xib. From the library drag one labels and two buttons.


Control + click the File's Owner object and drag it to the label then select currentNumber; now go from the minus and plus button to the File's Owner object and select decrementNumber for the minus button and incrementNumber for the plus button.


Save TutorialViewController.xib and close Interface Builder.

The Code

Open TutorialViewController.m. Below the implementation we need to create an integer called number and set the value to 0.
int number = 0;
We now need to create methods for when the increment and decrement buttons are pressed.
When the increment button is pressed we will increment the number integer by 1 then set the value of currentNumber to number by using a formatted string.
-(IBAction)incrementNumber:(id)sender {
 number++;
 [currentNumber setText:[NSString stringWithFormat:@"%d", number]];
}
and for decrement its the same but we decrement the number integer by 1.
-(IBAction)decrementNumber:(id)sender {
 number-;
 [currentNumber setText:[NSString stringWithFormat:@"%d", number]];
}

Build and Run

Press the Build and Run button (command + return) and your app will compile then open.


Download

Click Here 

 

No comments:

Post a Comment