Alert View
The basic method for constructing an alert view (UIAlertView) is initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:. The method for making a constructed alert view appear onscreen is show. The alert is automatically dismissed as soon as the user taps any button. Here’s an example (Figure 26-1):
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Not So Fast!"
message:@"Do you really want to do this tremendously destructive thing?"
delegate:self cancelButtonTitle:@"Yes"
otherButtonTitles:@"No", @"Maybe", nil];
[alert show];
The otherButtonTitles parameter is of indefinite length, so it must be either nil or a nil-terminated list (not an array!) of strings. The cancel button needn’t be titled “Cancel”; it is drawn darker than the other buttons and comes last in a column of buttons, as you can see from Figure 26-1. If there are more than two otherButtonTitles and a nil cancelButtonTitle, the last of the otherButtonTitles is drawn as if it were a cancel button; this code, too, produces Figure 26-1:
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Not So Fast!"
message:@"Do you really want to do this tremendously destructive thing?"
delegate:self cancelButtonTitle:nil
otherButtonTitles:@"No", @"Maybe", @"Yes", nil];If an alert view is to contain a text field, it probably should have at most one or two buttons, with short ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access