Tutorial details

HelloWorld | App Code for Sale | Preview

HelloWorld | iOS Tutorial

Hello word tutorial

Overview PAGE TOP

Hi everyone as promised i am posting our first project "helloworld".As we have previously discussed about the three files of your Xcode project ,they are

   ViewController.h
   ViewController.m
   ViewController.xib

So now create your new project with "helloworld" as your product name and select the ViewController.h file as below

Screen_Shot_2012-11-27_at_2.38.59_PM_1.jpg

So now we are going to declare the needed things in our program .So in my helloworld program am going to show an "label" with message "hello world" in the iphone simulator .

In the ViewController.h file under "@interface ViewController:UIViewController" , open a brace "{" then type the code

IBOutlet UILabel *lbl;

and now close the brace.Now lets look at the code .We can write the code in Xcode in two ways ,1.)Dynamic programming 2.)Xib IBOutlet

In Dynamic programming we create a "label" with user defined shape,size,colour, position on screen etc ,but in Xib IBOutlet we are just creating a label with predefined settings.

IBOutlet means InterfaceBuilder Outlet- it gives an permission from .h to .xib file, that is ,from .xib file we can access the declared identifier in .h file, in our case it is "lbl" .

Next comes the UILabel . Am creating an label ,so to declare an label we must call the "UILabel" class ,similarly for a button it is "UIButton" for a table "UITable" etc .

Now why do i put an "" before my label name. So here my name for label is "lbl" . I hope you know an concept in programming languages called the "pointers" . Which means it Points the address " .It is like if we just mention as "lbl" the process goes like ,it searches for the name "lbl" then goes to it's memory location then saves/fetches data.On the other hand if we create the name like this "lbl" then the process goes like ,it searched for the address of the variable then saves/fetches the data. So pointer variables are lot much faster than the normal variables.

So in objective c we always use pointer variables. And to end an coding we insert ";" .Then close the brace "}" .

And now our ViewController.h is over. Let's jump to the ViewController.m file

Screen_Shot_2012-11-27_at_3.06.44_PM_2.png

In the ViewController.m our main concentration must be in the -(void)viewDidLoad . When your application open whatever code written inside this gets executed.Let us go to this later. Now you just simply write the coding under this DidLoad function

lbl.text=@"hello world";

Now lets discuss about the above line. "lbl" is our label name declared in .h file . The thing is we called "text" property through (dot) operator. Let me make it simple to you, in objective c we call a property using ".(dot)" and we call an method by leaving a space .For e.g. i called an text property by using by label name like "lbl.text" ,similarly we can call a method by leaving an empty space and in beween the square braces "[ ] " ,for e.g.

"[lbl setHidden:(YES)];"

And now am adding an text string to my label name lbl.text=@"hello world";

Strings must start with an symbol "@" and must be in between quotes . In objective C we also use the symbol "@" for keywords like "@end" etc ,we will see that later.Now just remember that we use "@" for strings" .And .m is over .Let us jump to .xib .

Screen_Shot_2012-11-27_at_3.22.34_PM_3take.jpg

in .Xib you will be provided with user interface features in the bottom right pane like label,textfield,button etc. Now just drag and drop the "Label" from the right pane to the View present in the centre. That is the iphone screen.Now as i have discussed before we have given IBOutlet in our UILabel "lbl" so check out the screen shot below.

Screen_Shot_2012-11-27_at_3.25.21_PM_4.takejpg.jpg

The yellow square box is called the FILES OWNER . Right click on it to view the declared identifiers,functions in ViewController.h . Since we gave permission through IBOutlet and since our program is not dynamic programming ,the label "lbl"declared in .h file is visible in the files owner .Now just connect the "lbl" to the "Label" in the Iphone screen (View).Thats it we just completed everything . Now select the play/run button and the simulator opens and the output is displayed as below

Screen_Shot_2012-11-27_now.png

So finally we made the helloworld project . In future i will post sample codes and lets play around objective c basics . Please do comment for doubts !! C ya!!!

Reference PAGE TOP

http://xcodr.blogspot.in/2012/11/helloworld.html

0 Comments Leave a comment

Please login in order to leave a comment.

Newest first
!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.