Xamarin.iOS 显示模式警报对话框
示例
在iOS上处理用户输入之前,通常使用NSRunLoop显示模式UIAlertView来阻止代码执行。在苹果发布iOS7之前,它中断了很少的现有应用程序。幸运的是,有一种更好的方法通过C#的async/await实现它。
这是利用异步/等待模式来显示模式UIAlertView的新代码:
Task ShowModalAletViewAsync (string title, string message, params string[] buttons)
{
var alertView = new UIAlertView (title, message, null, null, buttons);
alertView.Show();
var tsc = new TaskCompletionSource ();
alertView.Clicked+= (sender, buttonArgs) => {
Console.WriteLine("User clicked on {0}", buttonArgs.ButtonIndex);
tsc.TrySetResult(buttonArgs.ButtonIndex);
};
return tsc.Task;
}
//Usage
async Task PromptUser() {
var result = await ShowModalAletViewAsync
("Alert", "Do you want to continue?", "Yes", "No"); //处理结果
}
热门推荐
10 幽默的伴郎祝福语简短
11 发给女儿生日简短祝福语
12 新年的祝福语简短的
13 下雪路滑祝福语简短
14 考试祝福语简短给对象
15 周岁生日祝福语简短男孩
16 韩语妹妹生日祝福语简短
17 讲课祝福语简短10字
18 送菜的祝福语简短霸气