Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

★★★[iPod Touch & iPhone developement ] Make your first application! [Objective C]★★★

How to make a Hello World application in Objective C for iPod Touch and iPhone

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯




Well first welcome to my tutorial on how to make your first application, a hello world in Objective C.

(Remember that this tutorial is beginner but if you don't know what Xcode is, this tutorial is probably not for you.)

Requirement:
Xcode


Part 1

To start, in Xcode click File > New Project and then select View-Based Application. Choose a name (FirstViewApp). Open Classes (Folder) and select FirstViewAppViewController.h. and paste the following IBOutlets, properties and IBAction in the .h file. It will looks like:

Code
@interface FirstViewAppViewController :
UIViewController {
IBOutlet UITextFidel *textField;
IBOutlet UILabel *label;

}
@property (nonatomic, retain) UITextField
*textField;
@property (nonatomic, retain) UILabel
*label;
- (IBAction) clickAction: (id)sender;

@end

Now add this to the corresponding .m file:

Code
@implementation FirstViewAppViewController
@synthesize textField, label;

- (void) clickAction: (id) sender{
label.text = textField.text;
//We hide the keyboard on button click.
[textField resignFirstResponder];
}



Part 2

Build the project. Now Interface Builder (IB) is aware of the new IBOutlets and IBAction.

Open the Ressources folder and click on FirstViewAppViewController.xib.
It will open IB. Drag a text field in the view designer.
Drag a Label just below the text field.
Now drag a Round Rect button bellow the label.
Click the button and open the insperctor (Use Shift + Command + I). Write a title for the button.
Note that you can edit the text size by clicking the text field then on the IB menu bar, click Font and Show Fonts.


Click FirstViewAppViewController.xib. in the small IB window, named with the xib name, expand the view node.
Now control drag from File's Owner to the UITextField node. A black pop up will appear with the outlet "textField" in it.
Drop the blue line on textField. Do the same or UILabel.
Now, Control + Drag from the UIButton to File's Owner.
Now we can interact with the UI components through code.



Part 3

Build and Run. Type something in the text field and click the button.
If you followed the tutorial correctly the text you entered should appear in the Label.

Thanks for following my tutorial.
--
Nice tutorial, Julie; There has never been a tutorial on iPhone/iTouch Application...

Keep it up!!
(Oct 31, 2010 12:33 PM)Sri Krishna Wrote:  Nice tutorial, Julie; There has never been a tutorial on iPhone/iTouch Application...

Keep it up!!

Thanks :)

I'm planning on making other tutorials like how to make a basic game and things like that.
--
Wow ! Awesome tutorial ! Very Detailed, Thank you !
This a great tutorial! +kudos
Ive been wanting to learn how to make one :)
Am I the only one that doesn't think this tutorial is any good? Not because there's things wrong with it, but because it's more of a follow this without proper explanations.

Also you shouldn't be using nonatomic, as far as I see it nonatomic is just an optimization (and one that should only be made at the end of the program). I've noticed lots of iphone tutorials use it constantly, probably because then there wasn't any easy way to implement mutlithreading, so not many did it and I guess it was safe to say you weren't going to fall into a trap so to speak. But now because of GCD, there's an easy way to implement multithreading, and so teaching people to use nonatomic and getting into the habit of using nonatomic at the start is bad. That's why you should do it at the end of the program, when you know where it can be used and not, also in most cases there isn't much of a performance gain to be made and there's better optimizations people should be making instead of (or with) that. And besides all that, it's something a beginner tutorial shouldn't be teaching anyway.
Thank's for this nice tut ...
Nice tutorial man. Never heard of this.Great share.
[Image: HpRYe.jpg]
very nice tut... this is great...
Thanks for the tut, I was wondering in what language they were made in.. Thanks.
great tutorial julie :) Thanks


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by amethystSep 17, 2021 02:58 PM 1 95 Sep 17, 2021 02:58 PM
Last Post: Sajuuk
[Java] by CryptAug 14, 2020 04:15 AM 6 261 Aug 14, 2020 04:15 AM
Last Post: Sonimnx
[Java] by TennoFeb 3, 2019 04:49 AM 4 307 Feb 3, 2019 04:49 AM
Last Post: Tenno