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 of
iPhone 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
![Beginner iPhone SDK Hello World Tutorial [Example & Code] icon smile Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sTGVpRWPNzDV6INuu7LX5ycAlP5MNJwKLwG-hhLaJhCEiq3SLAduh6pasGht_V-035hU3rkQy7ohgighd6eGjJvyXfYkCXP4upP2CMS6BAInZ6gFjWOVDKolY0aoNaptfw=s0-d)
.
Final output of hello world tutorial
![Hello world iPhone Tutorial Picture 25 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_un-WVW0byHfFsFTWaVQGmZ-UxnuSkAncx02OJNHoCb_8hI1OJQUff18vmqHYdxa-opFhWUD74hC6MDUVgnrzEnGJaiGk7jPWiJbVJhT9DPsCagvS1daCFigcgswnw96ahQXkoPkbUBhnkOyrR69AjB6IQUHU3wpKAgjX4X8HTY7zTRRg=s0-d)
Hello world iPhone tutorial Output
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.
![First iPhone application Picture 26 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_u0-2MfGUuODYJtpqu1bcF8rvhtpqD0blkNahSfp4GPnRZteUzOwvYlwJD6LhCXczX0S4FSqk3QBj12zkBQH9czowJwrTJvFdEsjb4yxM1ci9kS7SP4AO-R0-uRSWvu_Vl8VONfdJf8g5IgicRL_pQQ-jHtO-pP-0fTIl51bUwhdSiwFg=s0-d)
Create a new Xcode Project for iPhone application![Hello world iPhone Tutorial Picture 1 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_s_xf5W94XNEMFEEsYKdSLA3R1QDGctNaqBlm7L3fwQz08zWtQpT0zwYarBeVUD3hh3suLB5su-KhQTbr0U0Y2LfuZNbmp-hHqfZrzoZPSdx1HGj14CEszq_xtd2ZfTbT_qZQsNWMKVehHsS_IGq7PaIFU9eW95yhhu7dCs4-atgXGG=s0-d)
Select the basic design for your first iPhone application![Simple iPhone SDK Hello World Tutorial Picture 2 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uv1d7A0RYdmCloDz4S1-A7eomqv3VO8CVQbDKuitYxLI5nK1iTuHmLoEb_wJ4Ng4LxkzI-LtpNYhGapdKIAEOCYxewsaPWKg7x2QiOTfHiiYIneMXKyGMtHdo-sy2wFqNBr4049Jk5jQTDCUPW8kRoAbltKJNRD7orMs9NHCOHpWym=s0-d)
Name your first iPhone applcation![Getting started developing on the IPhone SDK Picture 3 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sSWCjWnnT_D7RjdbOoLg5f8B2MsqR6PP59Lra7_XBP_0MMAZLAJx_rejwhtrjhTiG-BaLpvURFyk-OaTjfM6jZXJnlOj_lhK5hh9hDzgEISUYSwHSHoEeazgJNyIU8EP2KF5xfIduVjNlBYhM-2Xdm68j4oMvGp0uyX0AfWCz9ghtV=s0-d)
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.
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;
Step 4:So your HelloWorldViewController.h file will look like this:
#import <UIKit/UIKit.h>
@interface HelloWorldViewController : UIViewController {
IBOutlet UITextField *txtUserName;
IBOutlet UILabel *lblUserTypedName;
}
- (IBAction) submitYourName;
@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.
![Structure of your iPhone application Picture 28 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vDU9_P2d9ePvG9H1AhRSM-W_uaEvEJ5J6AZgzdNowl3eVxnjX8ha4DzZia2s7LpE0cSncxHY5JgUCTye5QvN1pWE7V_3pk1egFD7WVVILi0wnkPi40A1TiTnBJ0Ukzj6e9VYxuB8kZcskjXDMX4ajyppUgbTdxBe67emLx1gB9-Du1=s0-d)
Structure of your iPhone application
![Interface builder Look Picture 8 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tLX9uBczMcJ6PJ2KaBU3xVzIKMmkYmN5ci1DwpFdkS5q0RfuH1HZrf4MDKTfTazpEgdTvAJCAyDgDuPeR5Dfhpo6Tf5k8TGvuy-Yx7Zd2b1Y7O8I0P_fNtfehT5NvNG61xRnwqN1hfsMRgA0cmERoSsZ7dNfgxfpox4u4qnkVRtlg=s0-d)
Interface builder Look
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”.
![Add label to your First iPhone application Picture 9 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sOGDaY1YjjR_Pb422lb8a9uw9BJ75h3XSIIU5Jre5HtuxLwPjY73_nd3RyC5H0ogQTYv-PKNaZPOt_t0861GKDg_79oqh6OwJZiJmfyGv3YoLeI82ZNd7NVknqACfHIzJo1BWpp9QwdFdBW5d4oqUWOGOcdbCf3KpBquo2XS4SULA=s0-d)
Add label to your First iPhone application
![Change text in your UILable Picture 10 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_u4vI9hTQcVImdWkjUcRtXXhsXTmTZYMLVQnG6RKYqqvXAWC91FNPeEhgFRTj1my-W0wFGGe_Wj7z4h-oek6XLNf7idGQ6k3BKKz-yMuu82CEciGWHRJskZgQMXgh5bea9as2B40oHOIGdPLuvURJUWPM808hEu2KZYtIiywIaRQtDlHQ=s0-d)
Change text in your UILable
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 Picture 11 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vL9AcvbxYbPsNFwOc6kEe5mt-BXbgYPo6CEepz3fcsaS4EcOFesybcvzr7cTlOEhVSzbTtvwYYAYcxtQQ62YA--suRhGDogwmSNE85dJ3_XGBKvLP_7nA7UVhpg5pNlP7Pi0i2oeKBm7mrzSrz5dYFU4kTkbOLqFeDyaQ2fQUNtFdeMQ=s0-d)
Add Text field to your first iPhone application
![Add label to your First iPhone application Picture 12 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sNBTUb0gwQyGatU_Uc2MG0N3gThmIMFMpDUWDbaPPQZq5PoIxP7gR_zsH4yPoqRKZsnAdNY9GlO9FAbNP_LjFXi4Qdd5M0mrKRgP-1IG6lzjygw3z37pONUOAoh6DAt8xnB3EwrHq157_4HB77tLc-bDHRmoGi40ZGHN5E6XzCsI6Z7Q=s0-d)
Add another label to your First iPhone application
![Change Label Width Picture 17 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sw8uq4rU7C4w8VJSIahsJvxbM8wGjT4GAM0MvvTOZ93x2YQKe7DXQq7oIADSbX8EagKvnhLxW6tkGPC5UndTp9lrN-NXiC4yUVjFZ2H9nQ677r_c0Nphf-kKkS2L37uKFuPgqUNbn_G-eIEICRpmYDOdEbVbDNqZK1DZCYJP1pAwtu5A=s0-d)
Change Label Width
![Center UILabel from Interface Builder Picture 18 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vCjUKrEgm8wO-lzX_GsAwz-YmgP4tFnlfaW0XgtU3CTNXlbnDJd2kIT_8FrDKzjLpwzlpBcQ4-bDCyIZd_dNR9CyvfVJUY9kGGxIRzcfCoo8ftghHq5Lt-cR-0Tva7Nsx4HEqGzw1rdJF0OZCg-hDNOemw-hjB2SzNGVHhKKdYE2Qguw=s0-d)
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”.
![Add button to your First iPhone Application Picture 19 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sHfsUcbIJqe-E4YfBbZrKqpCiwlxlVmMiJIWRfKUMfWydTjKaCl7C0dA9Ytc46TTyBMIUMozREqXnVCXANpWXPYVg1Jhn_CAnVcI3Kvo6hrjmGKa0i5cTcnTgVz-qa7SFmfmk6X7ZYZmL08qcvDJMsjjNHJLy19JszJu3TIL13EW2R=s0-d)
Add button to your First iPhone Application
![Change Text in your UIButton Picture 20 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tPtoOaOqw39WI0o0uqWlnZvGJTjefBSUGA_jcMBf08Kdva4hqF52jdTh1k9gh4Ed_fM5w8-PzIK9kS2bR7vAp5h6KbWcw-_pPhOzHJRrykUbQYu6XwKVxDyxBg7EkvbQLKZLceOcqMZ999FCMHy19MpYdQbQ4DGklWMxipqj2bKZJyTQ=s0-d)
Change Text in your UIButton
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
![Map your controller with Interface Builder Picture 13 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vtd_YG39PZ69MJiz601yoQIgnrYbk5kOilxukNJ7P5khN7MSYe6bDZ_ac1oFiwBeeJ68nQxyT2mdaLtgvnU3B5ZJC2Thphq91jm_xge3aObv0Bpgm9ewBpRSxZ8Ix3CdwcJRBZfL_jWT1X9R2TcEitUJucMB20H9W-5HhDKupVJhba8A=s0-d)
Map your controller with Interface Builder
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)
![Map your text field with Interface builder Picture 14 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sTxwIQIw3hQjKnp0GMGHZ_kqXG30mdu4MopNnm1eaH3Q2QosB-2z6A7xyJLqVA3WkqcVSI6gKQaCZ5ANJ4xri_d1G71zZJpGnIsxr1vNnQQ5AomN257otnRToU0Ff9pKmjOd4pPQBnE0oIYCDwpbh8Urw8tYmEfvPob2vxcCVwTGLyHQ=s0-d)
Map your text field with Interface builder
Step 12:Do the same with lblUserTypedName, select its radio and drag it to below label.
![Map your Label field with Interface builder Picture 15 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tiH9xXUgLDxtTecabRRWsFcZLtD3rpdcX1unwM2p949_i-WHSnnIHWl4X7R2dWVzgm7erQUnpYOhIDQ5L_6fcyRhxyv0NigDia1R1m5xBFlP3nEsKckUHzPNUoM9luIsfBF5VYhIESBKzwgXv0ryUXGLGA25g1QMcJ-8ckksDmMsV-Fg=s0-d)
Map your label field with Interface builder
Step 13:Now the last step is, click on submitYourName radio and drag it to the button and select touch down from the list.
![Map your button with Interface builder Picture 21 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_v9R_ujO0D_TzeQynFLmDo5edrl9WlA7untGfnospQRrb_iV4BkPFvCFjODWwaRlssvI-WJvfhJUwI5-1JT8hr33qFUHdETWpH6DO1MbCLlPlT2FrEZuMjP73Um7upNElNHQme9E1jBqYdDyZx6qhJ8Hb8HEJr9srmRwh2Toyc2nllS6g=s0-d)
Map your button with Interface builder
![Set action type of Button Picture 23 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_s6ebNtBqI7jTXx1D0a3C0J5VVdBFXRuAV1nVOEMfSltEXLl3X5tYdoBHVh-j7pRNlJ33xgrYIfITxREJ4EZCR-x9Ywd08kPZWjIMOEZ6IdU20U83XJNGn8w6IIJzkfEKZJG_kRWAPoW1dDV49pFD7joJVnGsy-dqitMHqKX1HZYPceng=s0-d)
Set action type of Button
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
![Your first iPhone application Running in simulator Picture 25 Beginner iPhone SDK Hello World Tutorial [Example & Code]](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_un-WVW0byHfFsFTWaVQGmZ-UxnuSkAncx02OJNHoCb_8hI1OJQUff18vmqHYdxa-opFhWUD74hC6MDUVgnrzEnGJaiGk7jPWiJbVJhT9DPsCagvS1daCFigcgswnw96ahQXkoPkbUBhnkOyrR69AjB6IQUHU3wpKAgjX4X8HTY7zTRRg=s0-d)
Your first iPhone application Running in simulator
iPhone hello world tutorial code
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