Create View-base application in iPhone

We are going to define view-base application template that we use in the application. We will see how the view and controller objects work together in an iPhone application.

We are going to define view-base application template that we use in the application. We will see how the view and controller objects work together in an iPhone application.

Step 1: Create a View-base application using the template . Name the project SimpleExample. 

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: Expand classes and notice Interface Builder created the SimpleExampleViewController class for you. Expand Resources and notice the template generated a separate nib, SimpleExampleViewController.xib for the SimpleExampleViewController.

Step 4: Open SimpleExampleViewController.h and add UILabel and one method for changing the label’s value. Make the label IBOutlet and method an IBAction. Make the following changes in the SimpleExampleViewController.h file.

#import <UIKit/UIKit.h>
@interface SimpleExampleViewController : UIViewController {
        IBOutlet UILabel *theLabel;
}
@property(nonatomic,retain) UILabel *theLabel;
-(IBAction) changeLabelValue :(id) sender;

Step 5: Open SimpleExampleViewController.xib file in the Interface Builder. Select library from the Tool menu and drag label from the library and place it to the view window, double click it and change the label name into “Hello iPhone!!!” . Now bring the Round Rect from the library and place it  below of the label. Double click the Round Rect and give the name “ClickMe” . Now single click the Round Rect and  bring up connection inspector, drap from the Touch Up Inside to the File’s Owner icon and select the  changeLabelValue: action. Save your .xib file and go back to the Xcode.

Step 6: Open the SimpleExampleViewController.m file and make the following changes:

-(IBAction) changeLabelValue :(id) sender
{
[theLabel setText:@"Welcome to the Real World!!!"];
UIButton *theBut = sender;
NSLog(theBut.currentTitle);
}

Step 7: Now compile and run the application in the simulator.

You can downloaded SourceCode from here SimpleExample 2

WP Greet Box icon
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic, and free programming tips and tricks and source code            snippets.

Leave a Reply

Security Code:

learn iphone programming

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Our Mobile Training Courses

EDUmobile.ORG offers the following 4 Mobile Training Courses. Our iPhone Training Course is very popular, with over 200 developers in training.

learn iphone programming
© 2010 EDUmobile.ORG