iOS Guides | Samples

MonoTouch.UIKit.UIAlertView Class

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

See Also: UIAlertView

Syntax

[MonoTouch.Foundation.Register("UIAlertView", true)]
[MonoTouch.ObjCRuntime.Deprecated(MonoTouch.ObjCRuntime.PlatformName.iOS, 9, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, "Use UIAlertController with a UIAlertControllerStyle.Alert type instead")]
[MonoTouch.ObjCRuntime.Unavailable(MonoTouch.ObjCRuntime.PlatformName.TvOS, MonoTouch.ObjCRuntime.PlatformArchitecture.All, null)]
public class UIAlertView : UIView, IDisposable

Remarks

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

The UIAlertView allows the application user to choose among alternative actions. The following code and image, taken from the "AlertViews" section of the "ios Standard Controls" sample illustrates the simplest use-case:

C# Example

UIAlertView alert = new UIAlertView () { 
	Title = "alert title", Message = "this is a simple alert"
};
alert.AddButton("OK");
alert.Show ();

An alternative to the UIAlertView is the UIActionSheet.

The application developer can use UIAlertViewStyles such as UIAlertViewStyle.PlainTextInput or UIAlertViewStyle.LongAndPasswordInput to allow the application user to enter values.

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 UIAlertViewDelegate 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 UIAlertView.WeakDelegate property.

Note to Inheritors

This class should not be subclassed.

Related content

Requirements

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

The members of MonoTouch.UIKit.UIAlertView 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 UIAlertView with the specified frame.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.
Constructor to initialize an alert view.

Public Properties

AlertViewStyleUIAlertViewStyle. The style of the alert view.
[read-only]
static
AppearanceUIAlertView+UIAlertViewAppearance. Strongly-typed property that returns the UIAppearance class for this class.
[read-only]
ButtonCountInt32. The number of buttons contained in the alert view.
CancelButtonIndexInt32. The index of the cancel button.
[read-only]
override
ClassHandleIntPtr. The handle for this class.
DelegateUIAlertViewDelegate. An instance of the MonoTouch.UIKit.UIAlertViewDelegate model class which acts as the class delegate.
[read-only]
FirstOtherButtonIndexInt32. The index of the first other button.
MessageString. Detailed text shown below the title in the alert view.
ShouldEnableFirstOtherButtonUIAlertViewPredicate. Delegate invoked by the object to get a value.
TitleString. A string shown in the title bar.
[read-only]
VisibleBoolean. Used to determine if the alert view is currently being displayed.
WeakDelegateNSObject. An object that can respond to the delegate protocol for this type

Public Methods

AddButton(String) : Int32
Adds a button to an alert view with the specified title.
static
AppearanceWhenContainedIn(params Type[]) : UIAlertView+UIAlertViewAppearance
Returns a strongly typed UIAppearance for instances of this class when the view is hosted in the specified hierarchy.
ButtonTitle(Int32) : String
Returns a button title by index.
DismissWithClickedButtonIndex(Int32, Boolean)
Closes an alert view with an optional animation.
static
GetAppearance(UITraitCollection) : UIAlertView+UIAlertViewAppearance
Returns an appearance proxy for the specified traits.
static
GetAppearance(UITraitCollection, params Type[]) : UIAlertView+UIAlertViewAppearance
Returns an appearance proxy for the specified traits when found in the containers containment hierarchy.
static
GetAppearance<T>() : UIAlertView+UIAlertViewAppearance
Obtains the appearance proxy UIAlertViewAppearance for the subclass of UIAlertView.
static
GetAppearance<T>(UITraitCollection) : UIAlertView+UIAlertViewAppearance
Obtains the appearance proxy UIAlertViewAppearance for the subclass of UIAlertView.
static
GetAppearance<T>(UITraitCollection, params Type[]) : UIAlertView+UIAlertViewAppearance
Obtains the appearance proxy UIAlertViewAppearance for the subclass of UIAlertView that has the specified trait collection when the view is hosted in the specified hierarchy.
GetTextField(Int32) : UITextField
Returns a text field for specified index.
Show()
Displays the alert view

Protected Methods

override
Dispose(Boolean)
Releases the resources used by the UIAlertView 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.