iOS Reference Library Apple Developer
Search

Where to Next?

This chapter offers suggestions as to what directions you should take next in learning about iOS development.

The User Interface

In this tutorial, you created a very simple iOS application. Cocoa Touch offers a rich development environment, though, and you’ve only scratched the surface. From here, you should explore further. Start with this application. As noted in the first chapter, the user interface is critical to a successful iOS application. Try to improve the user interface. Add images and color to the elements. Add a background image and an icon for the application. Look at the inspectors in Interface Builder to see how else you can configure elements.

Many iPhone applications support multiple orientations; applications for iPad should support all orientations. Make sure the view controller supports multiple orientations (see the shouldAutorotateToInterfaceOrientation: method), then (in Interface Builder) adjust your user interface to make sure that all the user interface elements are properly positioned if the view is rotated.

Creating User Interface Elements Programmatically

In the tutorial, you created the user interface using Interface Builder. Interface Builder allows you to assemble user interface components quickly and easily. Sometimes, however, you may want—or need—to create user interface elements in code (for example, if you create a custom table view cell you typically create and lay out the subviews programmatically).

First, open the MyViewController nib file and remove the text field from view.

If you want to create the entire view hierarchy for a view controller in code, you override loadView. In this case, however, you want to load the nib file then perform additional configuration (add another view). You therefore override viewDidLoad instead. (The viewDidLoad method gives you a common override point you can use whether you load the main view using a nib file or by overriding loadView.)

In MyViewController.m, add the following implementation of viewDidLoad:

- (void)viewDidLoad {
 
    CGRect frame = CGRectMake(20.0, 68.0, 280.0, 31.0);
    UITextField *aTextField = [[UITextField alloc] initWithFrame:frame];
    self.textField = aTextField;
    [aTextField release];
 
    textField.textAlignment = UITextAlignmentCenter;
    textField.borderStyle = UITextBorderStyleRoundedRect;
 
    textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.delegate = self;
    [self.view addSubview:textField];
}

Notice that there’s quite a lot of code compared with how easy it was to create and configure the text field in Interface Builder.

Build and run the application. Make sure it behaves as it did before.

Installing on a Device

If you have a suitable device connected to your computer via its 30-pin USB cable, and you have a valid certificate from the iOS Developer Program, set the active SDK for your project to “iPhone Device” (instead of “iPhone Simulator”) and build and run the project. Assuming your code compiles successfully, Xcode then automatically uploads your application to your device. For more details, see iOS Development Guide.

Additional Functionality

Next you can try expanding on the functionality. There are many directions in which you can go:

The most important thing is to try out new ideas and to experiment—there are many code samples you can look at for inspiration, and the documentation will help you to understand concepts and programming interfaces.




Last updated: 2010-07-01

Did this document help you? Yes It's good, but... Not helpful...