Action Sheet

The basic method for constructing an action sheet (UIActionSheet) is initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:. There are various methods for summoning the actual sheet, depending on what part of the interface you want the sheet to arise from. The following are appropriate on the iPhone, where the sheet typically rises from the bottom of the screen:


On the iPhone, far and away the most commonly used method. You will usually specify the root view controller’s view. Don’t specify a view whose view controller is contained by a view controller that hides the bottom of the interface, such as a tab bar controller or a navigation controller with a toolbar; if you do, some of the buttons may not function. (On recent iOS versions, you get a helpful warning in the console if you make this mistake: “Presenting action sheet clipped by its superview.”) Instead, specify the tab bar controller’s view itself, or the navigation controller’s view itself, or use one of the other methods. For example, in my Zotz app, which has a tab bar interface, the settings view controller summons an action sheet like this (Figure 26-2):

[sheet showInView: self.tabBarController.view];
An action sheet on the iPhone

Figure 26-2. An action sheet on the iPhone

showFromTabBar:, showFromToolbar:
On the iPhone, these cause the sheet to rise from the bottom of the screen, just like

Get Programming iOS 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.