WELCOME Abdennour : Software engineer

Apr 11, 2012

PeaceUponToWorld(HelloWorld) iPhone Application (Step By Step)

 Download Source Code
       
The world of iPhone is a world too superb.After GREAT Thanking ALLAH, My great thanks to the Dev Center Orange Tunisia which gives me the oppertunity to practice programming iphone thanks to their high level of material,
I decided to start with the simplest template and create a very, very easy application.

So, let's begin.
First off lets launch Xcode and get a new project going.
So
open XCode

Once you have selected it, click “Create a new Xcode Project…”

Select the project type  "View based application." Confirm your choice by double clicking.




Now, I have entered the name “PeaceUponToYou”  as my project name instead of "Untitled, then click "Save".




The project was presented with your newly created project in the XCode editor/IDE.




Deploy directories "classes", "Other Sources", "Resources" and concentrate on the three files
following:

1. The file PeaceUponToYouViewController.h can define all the properties and actions that will display the text "Peace Upon To You" on the screen of your iPhone simulator.




2. The file PeaceUponToYouViewController.m  in which you implement the code and methods predefined actions in the file header.
Remember that. H and. M always "walk" in pairs.






3. The file PeaceUponToYouViewController.xib  which is the user interface program that execute Interface Builder to create graphical interfaces for your application.








Open PeaceUpnToYouViewController.h , And Write This Code: 

#import <UIKit/UIKit.h>

@interface PeaceUponToYouViewController : UIViewController {
UILabel *mylabel;
UIButton *myButton;

}
@property (nonatomic,retain)IBOutlet UILabel *myLabel;
@property (nonatomic,retain)IBOutlet UIButton *myButton;
- (IBAction)buttonPressed:(id)sender;


@end


Open PeaceUponToYouViwController.m and write this code : 


#import "PeaceUponToYouViewController.h"

@implementation PeaceUponToYouViewController

@synthesize myLabel;
@synthesize myButton;

- (IBAction)buttonPressed:(id)sender
{
[myLabel setText:@"Peace Up To You"];
}
=>By analogy to the java world, buttonPressed is as a Listener

Now Double Click on PeaceUponToYouViwController.xib


=>and thereforeas you see, you use Interface Builder to "draw" your application:



4 windows will be opened :

1. Library : where you can select your graphic elements such as
UILabel, UITextField, UIButton, etc..

2. View  is somehow your iPhone screen. You slide your graphics here and
will organize so as to ease the use of your application.
3. PeaceUponToYouViewController.xib that displays according to the mode of viewing the elements present in the file. xib
4. Inspector (to view a press ⌘+1, or Tools> Inspector) which includes four other windows
segmented by tabs that let you edit the properties of your objects UILabel, View, etc..


In any case, we return to practice:

1) let’s go ahead and drag a Label from Library Window on to the screen(View)


The label now is on The Screen :
Then , Do the same thing  with a button and Change Text to "Show me" for Example.
And After building the project the Screen become  .... 



Now it is necessary to link your Action  to your showPeaceUponToYou method.



Simply select your button in which you previously entered the message "Show me", in Inspector, choose the tab "Connections" indicated by an arrow(Flèche). and a list of all possible actions on this button will appear.

How To do this ?
=> Right Click on "File's Owner" (which is in .xib Window)   and  make the combination of the button with your left mouse button depressed and [Ctrl] key on your Apple Mac computer and your loved without  releasing [Ctrl] key .


Choose "Touch Up Inside " as Action . 
That's Meaning ; When I click on Button , the Action will be excuted .

 Before Runtime , Save .xib File :

Before Click On the Button



After Click 
Congratulations!!!


                                                                    

No comments:

Post a Comment