Skip to main content

iPhone SDK Articles: First iPhone Application

Popularity Report

Total Popularity Score: 0

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Rank

Bookmark History

Saved by 5 people (-4 private), first by anonymouse user on 2008-10-20


Public Sticky notes

  • An iPhone application can only have one window. We will create views which can then be added to the window.
  • iPhone OS does not support memory management using the garbage collection feature that is in Mac OS Xv10.5 or later.
  • Highlighted by visualaudiotwo

    It is important that we save all the images, files, databases, and views in the "Resources" folder because all the iPhone apps run in its own sand box; which means they can only access files placed under the resources folder.

    Highlighted by visualaudiotwo

    he method applicationDidFinishLaunching method is called when the app is launched on the device or the simulator. The method is defined in "HelloUniverseAppDelegate.m" file which is found under the "Classes" folder

    Highlighted by visualaudiotwo

    An iPhone application has only one window (MainWindow.xib) unlike a desktop application which is created with multiple windows; however, we can create multiple views which are added to the window.

    Highlighted by visualaudiotwo

    Every nib file has atleast two files; File's Owner and First Responder which cannot be deleted.

    Highlighted by visualaudiotwo

    reate a view controller to manage the view.

    Highlighted by visualaudiotwo

    iew controllers play a very central role in create an iPhone application. They are responsible for managing a view, navigation and memory management. Every view is connected to a view controller.

    Highlighted by visualaudiotwo

    he UIKit provides a class UIViewController which hides most of the default behavior.

    Highlighted by visualaudiotwo

    The newly created class inherits from UIViewController which knows how to interact with a view.

    Highlighted by visualaudiotwo

    Now that we have our view and the controller class, there must be some way to connect these two files and we can do it by setting the class property of the File's Owner.

    Highlighted by visualaudiotwo

    Now we have to create variables for the controls we defined in our view. So we can connect these variables to the actual controls on the view.

    Highlighted by visualaudiotwo

    we need a way to control the view in the nib file from code and this is done by connecting the view instance variable to the view object in the nib. The connection is made using "outlets".

    Highlighted by visualaudiotwo

    The attribute retain while declaring the property tells the compiler to retain the object during assignment.

    Highlighted by visualaudiotwo

    his method is declared with a special keyword called IBAction, which tells the compiler to make this method available in the Interface Builder.

    Highlighted by visualaudiotwo

    All the variables above are marked with IBOutlet and Interface Builder will make these available to itself so proper connections can be made. We also have a method whose return type is IBAction (void); Interface Builder will also make this method available to itself so we can choose which event will call this method.

    Highlighted by visualaudiotwo

    he method also takes a parameter called "sender" which is the object which triggered the event.

    Highlighted by visualaudiotwo

    We first have to set the view controller to the File's Owner Proxy Object.

    Highlighted by visualaudiotwo

    Identity Inspector

    Highlighted by visualaudiotwo

    The easiest way to remember when to release objects is; if you create it then you own the object and hence you are responsible of releasing it.

    Highlighted by visualaudiotwo

    If you click on Build and Go, the view will not be visible because we have not yet added it to the window.

    Highlighted by visualaudiotwo

    The key thing to remember here is that the view message is passed to the "hvController" which returns the view and is added as sub view to the window. A valid view is returned because we created a connection from the view instance variable to the view in the nib file.

    Highlighted by visualaudiotwo