Feb 12, 2012

Introduction to iPhone development

Filled under:

The environment

Programming on the iPhone is Objective-C, a language that requires the use of X-Code development environment for Mac OS X. The programming must therefore pass through a Mac support.

Once you have a Mac available, you can visit the site of the development center from Apple and upload everything you need for the development, starting with iPhone SDK which contains the development environment Xcode and the iPhone simulator. It'll then install more than anything.

The interface of X-Code is not confusing to programmers because it resembles those of other IDE (development environment). The file tree is on the left unlike Visual Studio, and files are organized slightly differently. For example, we find records sources or even Framework but no file Header . Regardless, you adapt easily, it's very intuitive.

File creation

The source files

The programming part of X-Code is very simple to use. To add source files, just do Ctrl + click on the File Sources , and click Add New File ... ...

From there, a little window that asks you what type of file you want to create will appear. Simply select UIViewControllersubclass which is located in Cocoa Touch Class . Then click Next and verify that Also create "monfichier.h" at the top and your project in Target are checked. Finally, click Finish .

The views

To create a view, it happens the same way (or almost). Simply Ctrl + click on the folder Resources , then click Add New File ... ...

You will find your little window to add. Choose Empty XIB to add an empty view.

Programming files

The source files

The source files are divided into two categories:

The files. Pm

Files with the extension. H are also called header file . They can make the declaration of the various elements which are then visible in the view.

EXAMPLE:
To declare a label (text box of a line), we write IBOutlet UILabel * mylabel; in the @ interface {...}

To add properties, we write @ property (nonatomic, retain) UILabel * mylabel; before the @ end .

The files. M

Files with the extension. M are also called Objective-C class (or UIViewControllersubclass ). They are used to program the view, create function and use of the various elements previously reported in the file. H.

EXAMPLE:
To declare a function that would change the text loading the view, we write
- ( void ) {viewDidLoad
[Super viewDidLoad];
monlabel.text = @ "this is where I change my text" ;
}
The views

The views are simply items that are displayed on the screen of the iPhone. A view can consist of different elements such as images, buttons, text ...
To change views, you have to use Interface Builder.

When you want to modify a view, double click (Interface Builder will launch its own).

Once in the interface, you see the files in your view, but also a multitude of tools such as the Library (library components), or inspector of attributes. If you do not see these items, simply click on the top bar on Tools and you will see the list of available tools.

The Library

The library allows you to view all items available for your view, There are WebView (views for loading web pages), the TableView (list in table form) or even simple buttons (and more). .. Start by dragging and dropping an element View to your. xib containing the File's owner and the First Responder and open the view by double clicking.
A view will be displayed on your screen. You can drag and drop all items you need from the Library.

The Attributes Inspector

As its name suggests, the inspector of attributes used to define the properties of the elements!
Just click on an item to see the values ​​of the Inspector attribute change.

You must go through the Inspector of attributes to the relationship between your view and your source files: Click the File's owner of your view then click the identity of the inspector of attributes and select the name of your sources in Class .

The connection elements

Important thing that I long to find is the connection between code elements and the elements of sight. It's not very complicated actually ... Once you have made ​​your connection between your view and your view controller (source code), you just do Ctrl + click on the File's owner and drawing lines from circles that lie to the right of the elements, to the various elements of your sight.

Take Apple + Enter or click Build and Go to launch the application in the simulator. IPhone programming is now within your reach!

0 comments:

Post a Comment