This chapter offers suggestions as to what directions you should take next in learning about iOS development.
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.
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.
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.
Next you can try expanding on the functionality. There are many directions in which you can go:
Rather than using a view as a canvas on which to drop prebuilt user interface controls, you might try writing a custom view that draws its own content or responds to touch events. For inspiration, look at examples such as MoveMe and Metronome.
Although you used Interface Builder to layout the user interface for this application, many applications actually use table views to lay out the interface. This makes it easy to create an interface that extends beyond the bounds of the screen—allowing the user to easily scroll to reveal additional elements. You should first investigate how to create a simple list using a table view. There are several sample code projects that you can look at—including TableViewSuite—then you can create your own.
Navigation controllers and tab bar controllers provide an architecture that allow you to create drill-down style interfaces and let the user select different views in your application. Navigation controllers often work in conjunction with table views, but both navigation controllers and tab bar controllers work together with view controllers. Have a look at some of the sample applications—such as SimpleDrillDown—that use navigation controllers and expand on them to create your own applications.
You can often increase the size of your potential marketplace by localizing your application. Internationalization is the process of making your application localizable. To learn more about internationalization, read Internationalization Programming Topics.
Performance is critical to good user experience on iOS. You should learn to use the various performance tools provided with Mac OS X—in particular Instruments—to tune your application so that it minimizes its resource requirements.
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