Chapter 16. Custom UI Components

The SDK provides basic UI components for everyday use. Sometimes during the development of your projects, you need a UI component that is not provided by the SDK. In this chapter, we show how to marry various UI components and build custom reusable ones.

First, we show how to build an alert view with a text field in it, in Section 16.1. Next, Section 16.2 presents a table view inside an alert view. After that, Section 16.3 shows how to build a progress alert view. Finally, we summarize the chapter in Section 16.4.

Text Field Alert View

Often, you want to get a small piece of text from the user. You do not want to build a dedicated page for it, but you want a dialog box with a text field and OK/Cancel buttons. An example of this feature is the iTunes Store password prompt.

In this section, we will build such a custom UI component whose usage is shown in Figure 16.1.

The component can be configured for inputting telephone, password, or normal text. The trick is to add a UITextField as a subview to a UIAlertView instance.

Listing 16.1 shows the interface for our UI component, InputAlertView, a subclass of UIAlertView. Each instance of this class maintains a reference to the text field and its caller. The caller should implement the InputAlertViewDelegate protocol declared as follows:

@protocol InputAlertViewDelegate
-(void)handleEnteredValue:(NSString*)_value;
-(void)handleCancellation;
@end

The object using this class will be notified when the user taps the ...

Get iPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod touch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.