Xamarin.iOS 显示操作表
示例
在UIAlertController可用自iOS8上,您可以使用相同的警报对象无论是动作片还是比较经典的警报。唯一的区别是UIAlertControllerStyle创建时将其作为参数传递。
与此处提供的一些其他示例相比,此行从AlertView变为ActionSheet:
var alert = UIAlertController.Create(title, message, UIAlertControllerStyle.ActionSheet);
向控制器添加动作的方式仍然相同:
alert.AddAction(UIAlertAction.Create(otherTitle, UIAlertActionStyle.Destructive, (action) => {
//ExecuteSomeAction();
}));
alert.AddAction(UIAlertAction.Create(cancelTitle, UIAlertActionStyle.Cancel, null));
//如有必要,添加其他操作请注意,如果您有一个无参数的void方法,则可以将其用作的最后一个参数。.AddAction()
例如,假设我要在按“OK”时执行的代码:privatevoidDoStuff(){...}
UIAlertAction action = UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, DoStuff);
alert.AddAction(action);请注意,在创建动作时,我没有在DoStuff之后使用()。
呈现控制器的方式与其他任何控制器相同:
this.PresentViewController(alert, true, null);
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志