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