iOS Guides | Samples

MonoTouch.UIKit.UIActionSheet Class

A UIView that displays an action sheet with one or more buttons. (As of iOS 8, devs should use UIAlertController rather than this class.)

See Also: UIActionSheet

Syntax

[MonoTouch.Foundation.Register("UIActionSheet", true)]
[MonoTouch.ObjCRuntime.Unavailable(MonoTouch.ObjCRuntime.PlatformName.TvOS, MonoTouch.ObjCRuntime.PlatformArchitecture.All, null)]
public class UIActionSheet : UIView, IEnumerable

See Also

Remarks

As of iOS 8, app devs should use UIAlertController rather than this class. Extensions may not use this class at all.

The UIActionSheet control is a convenient way to allow the application user to choose among alternative actions. The following code and diagram are taken from the "Action Sheets" section of the "iOS Standard Controls" sample.

C# Example

protected void HandleBtnActionSheetWithOtherButtonsTouchUpInside (object sender, EventArgs e)
{
	actionSheet = new UIActionSheet ("action sheet with other buttons");
	actionSheet.AddButton ("delete");
	actionSheet.AddButton ("cancel");
	actionSheet.AddButton ("a different option!");
	actionSheet.AddButton ("another option");
	actionSheet.DestructiveButtonIndex = 0;
	actionSheet.CancelButtonIndex = 1;
	//actionSheet.FirstOtherButtonIndex = 2;
	actionSheet.Clicked += delegate(object a, UIButtonEventArgs b) {
		Console.WriteLine ("Button " + b.ButtonIndex.ToString () + " clicked");
	};
	actionSheet.ShowInView (View);
	
}

The MonoTouch API supports two styles of event notification: the Objective-C style that uses a delegate class or the C# style using event notifications.

The C# style allows the user to add or remove event handlers at runtime by assigning to the events of properties of this class. Event handlers can be anyone of a method, an anonymous methods or a lambda expression. Using the C# style events or properties will override any manual settings to the Objective-C Delegate or WeakDelegate settings.

The Objective-C style requires the user to create a new class derived from UIActionSheetDelegate class and assign it to the UIKit.Delegate property. Alternatively, for low-level control, by creating a class derived from NSObject which has every entry point properly decorated with an [Export] attribute. The instance of this object can then be assigned to the UIActionSheet.WeakDelegate property.

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.UIKit.UIActionSheet are listed below.

See Also: UIView

Public Constructors

Default constructor that initializes a new instance of this class with no parameters.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
Initializes the UIActionSheet with the specified frame.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.
Initialize an UIActionSheet with a title.
Initialize an UIActionSheet with a title and a delegate that will handle taps.
Initializes a UIActionSheet instance.
Initializes a UIActionSheet instance.

Public Properties

[read-only]
static
AppearanceUIActionSheet+UIActionSheetAppearance. Strongly-typed property that returns the UIAppearance class for this class.
[read-only]
ButtonCountInt32. The number of buttons on an action sheet. (read only)
CancelButtonIndexInt32. Returns the index of the cancel button.
[read-only]
override
ClassHandleIntPtr. The handle for this class.
DelegateUIActionSheetDelegate. An instance of the MonoTouch.UIKit.UIActionSheetDelegate model class which acts as the class delegate.
DestructiveButtonIndexInt32. Returns the index of the destructive button.
[read-only]
FirstOtherButtonIndexInt32. The index of the first custom button. Read-only.
StyleUIActionSheetStyle. The presentation style of this UIActionSheet.
TitleString. The title that will be displayed in the action sheet.
[read-only]
VisibleBoolean. A property indicating if the action sheet is displayed.
WeakDelegateNSObject. An object that can respond to the delegate protocol for this type

Public Methods

Add(String)
Adds a button with the specified text.
AddButton(String) : Int32
This method will add a custom button to an action sheet.
static
AppearanceWhenContainedIn(params Type[]) : UIActionSheet+UIActionSheetAppearance
Returns a strongly typed UIAppearance for instances of this class when the view is hosted in the specified hierarchy.
ButtonTitle(Int32) : String
Retrieves the title of a button at a specified index.
DismissWithClickedButtonIndex(Int32, Boolean)
Will dismiss the action sheet, optionally animated if specified.
static
GetAppearance(UITraitCollection) : UIActionSheet+UIActionSheetAppearance
Returns an appearance proxy for the specified traits.
static
GetAppearance(UITraitCollection, params Type[]) : UIActionSheet+UIActionSheetAppearance
Returns an appearance proxy for the specified traits when found in the containers containment hierarchy.
static
GetAppearance<T>() : UIActionSheet+UIActionSheetAppearance
Obtains the appearance proxy UIActionSheetAppearance for the subclass of UIActionSheet.
static
GetAppearance<T>(UITraitCollection) : UIActionSheet+UIActionSheetAppearance
Obtains the appearance proxy UIActionSheetAppearance for the subclass of UIActionSheet.
static
GetAppearance<T>(UITraitCollection, params Type[]) : UIActionSheet+UIActionSheetAppearance
Obtains the appearance proxy UIActionSheetAppearance for the subclass of UIActionSheet that has the specified trait collection when the view is hosted in the specified hierarchy.
GetEnumerator() : IEnumerator
Obtains an enumerator that returns the button titles.
ShowFrom(UIBarButtonItem, Boolean)
Displays an action sheet from a bar button.
ShowFrom(RectangleF, UIView, Boolean)
This method will display an action sheet, originating from the specified area on a view.
ShowFromTabBar(UITabBar)
Shows the UIActionSheet from the specified UITabBar.
ShowFromToolbar(UIToolbar)
This will display an action sheet, originate from the specified tab bar.
ShowInView(UIView)
Displays an action sheet in a specified view.

Protected Methods

override
Dispose(Boolean)
Releases the resources used by the UIActionSheet object.

Public Events

CanceledEvent raised by the object.
ClickedEvent raised by the object.
DismissedEvent raised by the object.
PresentedEvent raised by the object.
WillDismissEvent raised by the object.
WillPresentEvent raised by the object.