Blog Archives
Create Your First iPhone App – Steps 3 of 3 Posted by admin Saturday May 9, 2009 Tags: Java Quotes, Mobile Application Development, iPhone Comments: No Comments
Now you get to add your nib file. You’ll be using the interface builder that doesn’t generate source code. You can, however, manipulate objects and then save them in the nib file. But first you have to create the nib file by going to developer/applications to launch the Interface Builder. You then need to select “Cocoa Touch” in the templates selection window and then select to view the template. You then choose File > new.
Next, you’ll see three objects and will choose “view.” But before you edit the view, you will need to save the file in your project director. “ControllerView” is a good file name. It must match the name you created when you had to create a file at the initWithNibName: bundle phase. When Interface Builder asks you if you want to save it, you do. Make sure you still have Xcode running. You also want to confirm the file is listed in the project files listing.
Configuring the file’s owner
You have to configure the file’s owner next and you do this by selecting the “File’s Owner” icon in the Interface Builder and then choose tools> identity inspector. The identity inspector will then show.
In the class field of the class identity section, enter MyViewController.
Connecting the view outlet
The only connection left is the view outlet. When you are in the Interface Builder, you need to drag the “File’s Owner” file to “view.” The Interface Builder will now show that there is only one outlet available. Click on “view” The view icon’s quick flash means that the nib file is loaded. You can now save the file. Click the Build and Go icon in the toolbar so that you can compile and run the application. Compilation should be error free and a white screen present in the simulator.
The view controller will load the nib file automatically.
Adding user interface elements
Now you will go to the Interface Builder and choose tools > Library to display the library window. You can then drag view items from the library and drop them onto the view. You can then resize and reposition. You can also add a text field, button, or label by typing UI and what you want (example: UITextField). You can customize your entire screen.
When you are in the view section during your changes, you want to choose “Clear Context” before drawing each element so that the previous string is removed before creating a new one. When you are finished, save your file.
Make connections
You make connections by dragging and dropping. You can do such things as connect the Lable and TextField. When you do such things as resize, you can see what outlets are available to you.
Once you have made connections and made changes that you need to make to your application, you can then test the application by building and running it. You should find that everything is working properly within the application. If you do find any errors, you can go back and make changes to get rid of those errors.
Create Your First iPhone App – Steps 2 of 3 Posted by admin Saturday May 9, 2009 Tags: Mobile Application Development, iPhone Comments: No Comments
You’ve already set up the basic application environment by this point. You have your application object, you can connect to the window server, you’ve established the run loop, etc. Application bootstrapping is simply a process of the application tightening its boot straps. What happens is an instance of UIApplication is created, which scans the application’s Info.plist file. This file is simply a dictionary that contains information about the application. You may even see the name of the “nib file,” which is something you’ll see later on. Nib files contain object and user interface elements.
Now, you may see a nib file in a main window that says “MainWindow.xib.” There is a group of resources here that displays several forms of information. Once you are finished doing any customization that you wish to do to this section, your application object will send its delegate a message, later creating a “view controller” object.
Adding the View Controller
The view controller is very important to your iPhone app. The controller establishes a view and also helps in memory and navigation management. So next in Xcode you need to select the project or the Classes group folder. The new files will be added to what you select. You will: choose file > New File and in the New File Window. You now need to select the Classes group labeled “Cocoa Touch” and then select UIViewController subclass.
You now click “next” and assign a new file name. You have to create both .m and .h files, so be sure to do that. You then click “finish.”
Add a View Controller Property
It is ideal that the view controller lasts as long as the application does. You can add it as an instance variable to the application’s delegate. You do this by importing the file’s header by entering into the application’s delegate header file (file name ends in .h). You then add the forward declaration before the interface declaration for your file. You will, however, have to add the following lines in between the braces:
-
MyViewController *myViewController;
-
@property (nonatomic retain) MyViewController *myViewController ((goes before the closing brace, but before @end).
You will then have to create an instance. That is done by adding this code to applicationDidFinishLaunching:
MyViewController *aViewController = [[MyViewController alloc]
initWithNibName:@”ControllerView” bundle:[NSBundle mainBundle]];
self.myViewController = aViewController;
[aViewController release];
There is a lot going on in that little bit of code. It is important to your application. Once you release the view, you then add this code: UIView *controllersView = [myViewController view];
[window addSubview:controllersView];
Follow these steps and you have finished setting up your view controller:
-
Import the header of MyViewController with this: #import “MyViewController.h”
-
Tell the compiler to synthesize the accessor method for the view controller at the @implementation block with this: @synthesize myViewController;
-
Release the view controller in the dealloc method with this: [myViewController release];
You can now compile your project by clicking “Build” in the toolbar of your project’s window. Don’t try to run the application in the iPhone Simulator because it won’t work. You haven’t provided the ControllerView nib file yet, so it will crash.

