Embedding UITables into UIAlertViews
The newer Apple firmware will create a table in your UIAlertView automatically if you create a more than the number of buttons that fit onto the alert. Note that this number is different in landscape and portrait modes. I found the implementation to be very unappealing for a few reasons. First of all, you won’t really know if you will have buttons or a table until after you compile and test the application. Plus, if you want to display a table, but you only have a few options, then there’s no real way to get that with the standard UIAlertView. And finally, what if you had wanted to customize the table with colored cells, custom cells with images on them, or take advantage of the editing properties of the table and its “Swipe to delete” feature? What if you want a table with multiple sections? You would be able to do none of the above with the standard UIAlertView.
So instead, I decided the best option would be to create another custom UIAlertView whose sole purpose is to display a table.

Don’t use UITableViewController. Really.
I was hesitant to even begin writing this blogpost for two reasons. First of all, I knew it would be short. More importantly, though, it’s because I know some people swear by the opposite. However, I must insist that you should never use a UITableViewController in your iPhone applications.
Let’s go over the reasons to use a UITableViewController.
- It’s a subclass of UIViewController, so it’s simple to use.
- UITableViews must have a delegate and a datasource. UITableViewControllers automatically conform to the requisite protocols. The file template even comes with the necessary methods included.
Really, when you think about them, both of those two points are non issues. If UITableViewController is a subclass of UIViewController, why not just use a UIViewController with a UITableView on top of it? Also, conforming to to the delegate and datasource protocols is as simple as adding
Let’s now cover a few reasons why you won’t want to use a UITableViewController.
Shrinking Tables! (As seen in Spotlight)
Want to create tables as seen in Spotlight or Weather? It’s easier done than said : )
Note, this uses the Spotlight “cheater” method of simply drawing some pseudo corners over the table, as opposed to the Weather.app approach of masking off the table to remove corners. That said, as long as you’re using solid colors, the result will be identical.
First off, we want to open a new view controller based application. and slap in a simple UITableView with the grouped style. Go ahead and add the UITableView as a subview of your viewController.view.
Next, we’ll place a call our getCornersforRect:withColor: message. This will construct a UIImage of the corners that we want to apply. That image will be added to a new UIImageView that will be added on top of our UITableView. Read more
