Add And Subtract Number In iPhone

In this application  we will see how to add or subtract number in the program. This is a very easy application. Just have a look.

Step 1: Create a View base application using template. Give the application name “StartCount”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: In the StartCountViewController.h file we have added UILabel for display the number and add two methods for addition, subtraction. Now make the following changes in the file.

 

 

 

Step 4: Double click your StartCountViewController.xib file and open it to the Interface Builder. Drag two Round Rect from the library and place it to the view window. Double click the Round Rect and change the name into the AddNumber and SubtractNumber. Now drag the label from the library and place it to the view window, select the label and bring up Attributes Inspector and change the text into “0”. Select AddNumber Round Rect and bring  up Connection Inspector, connect TouchUpInside  to the File’s owner icon, select addNumber. Do it for one more time for SubtractNumber Round Rect and select subtractNumber. Next connect from the File’s Owner icon to the label and select startCount. Now save the nib file, close it and go back to the Xcode.

Step 5: In the StartCountViewController.m file make the following changes.

 

 

 

Step 6: Compile and run the application, see the output on the simulator.

downloaded SourceCode from here StartCount 2

Leave a Comment:

1 comment
Juan says January 26, 2011

Can’t run it, won’t compile.
I get an error that ‘gt’ undeclared. I’m assuming it’s the >= 999 thing up there.
If I take it out, nothing happens.

Good attempt, but you may want to revise it.
Using Xcode 3.2.4 here

Reply
Add Your Reply