In iPhone in Action, our main purpose was to step through all the major ways that you could develop on the iPhone. In the process, we did our best to discuss as many UIKit and Foundation objects as we could, but inevitably there were many that we didn't have space to cover.
Thus, the "SDK Missing Classes" series of articles that we've planned for this blog, which will (eventually) step through all the classes of objects that we didn't talk about, discussing what they are and how to use them.
Today I'm going to start out with an introduction to UIAlertView.
If you've ever wanted to send some information to your user, but you don't want to maintain a status line at all time, then the UIAlertView is the thing for you. It's a pop-up window which will appear above your application view. It can contain a title, some content, and one or more buttons.
I was recently coding a somewhat complex application which included a table view under a tab bar controller. Each element in the table led to more information, but I didn't want to make things yet more complex by introducing a navigation controller as well. So, instead I fell back on a UIAlertView:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *charAlert = [[UIAlertView alloc]
initWithTitle:[[hsList objectAtIndex:indexPath.row]
objectForKey:@"name"]
message:[NSString stringWithFormat:@"%@ %@",
[[hsList objectAtIndex:indexPath.row]
objectForKey:@"name"],
[[hsList objectAtIndex:indexPath.row]
objectForKey:@"info"]]
delegate:nil
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
[charAlert show];
[charAlert autorelease];
}
This was pretty much a UIAlertView at its simplest. It contained a title and a message, both filled in from a database. Under that was a button labeled "Done" which dismissed the UIAlertView (with no additional work on my part).
At this simple level, a UIAlertView can very useful for your program. It can be used to simplify table selection (as I did here) or it can be used to alert a user to status changes in your program. Once you call it up, you don't have to worry about anything else.
However, there's a bit more that you can do in a UIAlertView. In our book, Christopher & I always said at this point that you should refer to the class reference for additional information. However, now that we have a blog with potentially infinite space, we can get into specifics. In this case I'm going to return in about a week to talk about the more complex possibilities you can indulge in when using a UIAlertView.

Great book! I've been reading the early access and got the book a few days ago. It'd be great to see some postings about how to display a controllerview similar to the one that shows up when you are calling someone. Looking forward to part two!
Posted by: Tony | January 08, 2009 at 01:47 AM