Introduction:
I am going to show you the simplest way to create hello world iPhone tutorial. I will write few more tutorials on the basic ofiPhone Development. So this tutorial is an absolute beginner guide for iphone development. To get start with iPhone development you need to have iPhone SDK which you can get from here (http://developer.apple.com/iphone). To download it you need to have a apple developer account which is free for everyone. To test the code on device (iPhone) you need to buy a developer license which cost you 99$ or 299$ for enterprise.
Getting Started with iPhone Development:
To start with hello world iPhone tutorial, you should read the “getting started with iPhone” tutorial which covers the things you need to know before starting development for iPhone( You can also watch the video tutorial of “Getting Started with iPhone” ). I also write a tutorial for businessman and designer to know about the iPhone development cycle (“iPhone Development Guide” ). So if you are a beginner for iPhone, you should read my tutorial before starting iPhone development.
Idea of this tutorial:
There are already many tutorials on hello world in iPhone but I want to write a very basic tutorial on iPhone sdk which will cover xcode, iphone project files and interface builder. This is a basic hello world tutorial which will be extended to a big project later on. So before reading other tutorials on my blog I highly recommended you to read this beginner’s Guide toiPhone development. OR you can watch the video tutorial here if you have no time to follow easy steps .
Final output of hello world tutorial
Simple Steps to create hello world iPhone application
Step 1:If you have read the getting started tutorial, then you have a xcode installed on your mac machine. Open the Xcode and click on File > New Project. Select “View-Based Application” and click on “Choose..” button. Name this project “Hello World” and click “Save” button. Now you have a template for your hello world iphone project.
Create a new Xcode Project for iPhone application
Select the basic design for your first iPhone application
Name your first iPhone applcation
Xcode project template created
Step 2:Now click on Build and Go button to run this template application. It will start the iPhone simulator and you can see a gray screen on that. Click on Home button and it will show you a HelloWorld icon on the dash board of iPhonesimulator. If you click on it again, it will open the application again. iPhone simulator is best tool to test your applicationbefore you deploy it on your device for testing or even before submitting to apple store.
Build your First iPhone application
Output of your first iPhone application
Press this button to quit your first iPhone application
Step 3:Now open Xcode project and select HelloWorldViewController.h file and type the following code inside interface:
IBOutlet UITextField *txtUserName;
IBOutlet UILabel *lblUserTypedName;
Also write this method before end of this class
- (IBAction) submitYourName;
IBOutlet UILabel *lblUserTypedName;
Also write this method before end of this class
- (IBAction) submitYourName;
Step 4:So your HelloWorldViewController.h file will look like this:
#import <UIKit/UIKit.h>
@interface HelloWorldViewController : UIViewController {
IBOutlet UITextField *txtUserName;
IBOutlet UILabel *lblUserTypedName;
}
IBOutlet UITextField *txtUserName;
IBOutlet UILabel *lblUserTypedName;
}
- (IBAction) submitYourName;
@end
@end
Step 5:Now open HelloWorldViewController.m file and type this method before @end
- (IBAction) submitYourName;{
lblUserTypedName.text = txtUserName.text;
}
Step 6:Now lets start some design on interface builder. For that open your xcode project and in “Group & Files” looked at bottom, you will see “NIB Files”, expand it and you will see two design files for your classes. One is the MainWindow.xib which is the main window or entry point to your application. Other one is HelloWorldViewController.xib file which is mapped to your controller class “HelloWorldViewController.h. For now I just want to change in HelloWorldViewController.xib file. Double click on that file to open it inside interface builder.
Step 7:Click on Tools and select Libaray (cmd + shift + L) and drag the text field to your view. As text field is already selected, click on Tools>Inspector (cmd + 1) and in Text field type “Your Name”.
Step 8:Now drag the TextField from Library to your view (cmd+shift+L) and also drag another Label inside view. Make sure label is selected, Click on tools and select “Size Inspector” (cmd + 3) and change the width of this text field to 250. Also go to tools and select Inspector, change the layout to center.
Add Text field to your first iPhone application
Add another label to your First iPhone application
Change Label Width
Center UILabel from Interface Builder
Step 9:Last thing is to drag a button to the view (19) and then open Inspector again by selecting tools>Inspector. In Title type “Submit”.
Step 10:Now map the controller class variable function and methods with interface builder. Select File’s Owner in Interface builder and select connection inspector from Tools cmd + 2
Step 11:Now you can see that two new variables are added in connection inspector txtUserName and lblUserTypedName. Click on txtUserName radio button and drag it to text field in view (as you can see in the image)
Step 12:Do the same with lblUserTypedName, select its radio and drag it to below label.
Step 13:Now the last step is, click on submitYourName radio and drag it to the button and select touch down from the list.
Step 14:Now close the interface and open xcode. Either press cmd + r or cmd + enter or simply press of “build and go” button to run this hello world application. It will open the simulator in iPhone.
Final output
Final output
iPhone hello world tutorial code
You can grab this code from here.
Now watch me doing it
Click on this link to view the video screen cast for hello world iPhone application tutorial.
0 comments:
Post a Comment