iPhone OS Reference Library Apple Developer Connection spyglass button

UIActionSheet Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iPhone OS 2.0 and later.
Declared in
UIAlert.h
Related sample code

Overview

Use the UIActionSheet class to implement an action sheet that displays a message and presents buttons that let the user decide how to proceed. An action sheet is similar in function but differs in appearance from an alert view.

Use the properties and methods in this class to set the message, set the style, set the delegate, configure the buttons, and display the action sheet. You must set a delegate if you add custom buttons. The delegate should conform to the UIActionSheetDelegate protocol. When you display an action sheet, you can optionally animate it from the bottom bar or an arbitrary view. How the action sheet is animated depends on the bar style or the action sheet style you set.

Tasks

Creating Action Sheets

Setting Properties

Configuring Buttons

Displaying

Dismissing

Properties

For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.

actionSheetStyle

The receiver’s style.

@property(nonatomic) UIActionSheetStyle actionSheetStyle
Discussion

See UIActionSheetStyle for the possible values.

Availability
Related Sample Code
Declared In
UIAlert.h

cancelButtonIndex

The index number of the cancel button.

@property(nonatomic) NSInteger cancelButtonIndex
Discussion

The button indices start at 0. If -1, then the index is not set.

Availability
Declared In
UIAlert.h

delegate

The receiver’s delegate or nil if it doesn’t have a delegate.

@property(nonatomic, assign) id<UIActionSheetDelegate> delegate
Discussion

See UIActionSheetDelegate Protocol Reference for the methods this delegate should implement.

Availability
Declared In
UIAlert.h

destructiveButtonIndex

The index number of the destructive button.

@property(nonatomic) NSInteger destructiveButtonIndex
Discussion

The button indices start at 0. If -1, then the index is not set. This property is ignored if there is only one button. The default value is -1.

Availability
Related Sample Code
Declared In
UIAlert.h

firstOtherButtonIndex

The index of the first other button. (read-only)

@property(nonatomic, readonly) NSInteger firstOtherButtonIndex
Discussion

The button indices start at 0. If -1, then the index is not set. This property is ignored if there are no other buttons. The default value is -1.

Availability
Declared In
UIAlert.h

numberOfButtons

The number of buttons on the action sheet. (read-only)

@property(nonatomic, readonly) NSInteger numberOfButtons
Availability
Declared In
UIAlert.h

title

The string that appears in the receiver’s title bar.

@property(nonatomic, copy) NSString *title
Availability
Declared In
UIAlert.h

visible

A Boolean value that indicates whether the receiver is displayed. (read-only)

@property(nonatomic, readonly, getter=isVisible) BOOL visible
Discussion

If YES, the receiver is displayed; otherwise, NO.

Availability
Declared In
UIAlert.h

Instance Methods

addButtonWithTitle:

Adds a button to the receiver with the given title.

- (NSInteger)addButtonWithTitle:(NSString *)title

Parameters
title

The title of the new button.

Return Value

The index of the new button. Button indices start at 0 and increase in the order they are added.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Declared In
UIAlert.h

buttonTitleAtIndex:

Returns the title of the button at the given index.

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex

Parameters
buttonIndex

The index of the button. The button indices start at 0.

Return Value

The title of the button specified by index buttonIndex.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Declared In
UIAlert.h

dismissWithClickedButtonIndex:animated:

Dismisses the receiver, optionally with animation.

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

Parameters
buttonIndex

The index of the button that was clicked just before invoking this method. The button indices start at 0.

animated

YES if the receiver should be removed by animating it first; otherwise, NO if it should be removed immediately with no animation.

Availability
  • Available in iPhone OS 2.0 and later.
Declared In
UIAlert.h

initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:

Convenience method for initializing an action sheet.

- (id)initWithTitle:(NSString *)title delegate:(id < UIActionSheetDelegate >)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...

Parameters
title

The string that appears in the receiver’s title bar.

delegate

The receiver’s delegate or nil if it doesn’t have a delegate.

cancelButtonTitle

The title of the cancel button or nil if there is no cancel button.

Using this argument is equivalent to setting the cancel button index to the value returned by invoking showInView: specifying this title.

destructiveButtonTitle

The title of the destructive button or nil if there is no destructive button..

otherButtonTitles,

The title of another button.

Using this argument is equivalent to invoking showInView: with this title to add more buttons.

...

Titles of additional buttons to add to the receiver, terminated with nil.

Return Value

Newly initialized action sheet.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Related Sample Code
Declared In
UIAlert.h

showFromTabBar:

Displays the receiver using animation by originating it from the specified tab bar.

- (void)showFromTabBar:(UITabBar *)view

Parameters
view

The tab bar that the receiver originates from.

Discussion

The style of the animation depends on the style of the tab bar, not the receiver.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Declared In
UIAlert.h

showFromToolbar:

Displays the receiver using animation by originating it from the specified toolbar.

- (void)showFromToolbar:(UIToolbar *)view

Parameters
view

The toolbar that the receiver originates from.

Discussion

The style of the animation depends on the style of the toolbar, not the receiver.

Availability
  • Available in iPhone OS 2.0 and later.
See Also
Declared In
UIAlert.h

showInView:

Displays the receiver using animation by originating it from the specified view.

- (void)showInView:(UIView *)view

Parameters
view

The view that the receiver originates from.

Discussion

The style of the animation depends on the actionSheetStyle property.

Availability
  • Available in iPhone OS 2.0 and later.
Related Sample Code
Declared In
UIAlert.h

Constants

UIActionSheetStyle

Specifies the style of an action sheet.

typedef enum {
   UIActionSheetStyleAutomatic        = -1,
   UIActionSheetStyleDefault          = UIBarStyleDefault,
   UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
   UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,
} UIActionSheetStyle;
Constants
UIActionSheetStyleAutomatic

Takes the appearance of the bottom bar if specified; otherwise, same as UIActionSheetStyleDefault.

Available in iPhone OS 2.0 and later.

Declared in UIAlert.h.

UIActionSheetStyleDefault

The default style.

Available in iPhone OS 2.0 and later.

Declared in UIAlert.h.

UIActionSheetStyleBlackTranslucent

A black translucent style.

Available in iPhone OS 2.0 and later.

Declared in UIAlert.h.

UIActionSheetStyleBlackOpaque

A black opaque style.

Available in iPhone OS 2.0 and later.

Declared in UIAlert.h.

Availability
  • Available in iPhone OS 2.0 and later.
Declared In
UIAlert.h


Last updated: 2009-03-31

Did this document help you? Yes It's good, but... Not helpful...