xamarin.ios – Alerts – Display an Action Sheet

The UIAlertController available since iOS8 allows you to use the same alert object for either Action sheets or more classic alerts. The only difference is the UIAlertControllerStyle passed as a parameter when creating.

This line changes from an AlertView to an ActionSheet, compared to some other examples available here :

var alert = UIAlertController.Create(title, message, UIAlertControllerStyle.ActionSheet);

The way you add actions to the controller is still the same :

alert.AddAction(UIAlertAction.Create(otherTitle, UIAlertActionStyle.Destructive, (action) => {
    // ExecuteSomeAction();
alert.AddAction(UIAlertAction.Create(cancelTitle, UIAlertActionStyle.Cancel, null));

//Add additional actions if necessary

Note that if you have a parameterless void method, you can use it as the last parameter of the .AddAction().

For example, let’s assume I want the code of private void DoStuff(){...} to be executed when I press "OK" :

UIAlertAction action = UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, DoStuff);

Notice I’m not using the () after DoStuff in the creation of the action.

The way you present the controller is done the same way as any other controller :

this.PresentViewController(alert, true, null);

if you want to reproduce, please indicate the source:
xamarin.ios – Alerts – Display an Action Sheet - CodeDay