gpt4 book ai didi

xamarin.ios - 是/否确认UIAlertView

转载 作者:行者123 更新时间:2023-12-04 16:15:25 26 4
gpt4 key购买 nike

我通常使用以下代码进行确认警报

int buttonClicked = -1;
UIAlertView alert = new UIAlertView(title, message, null, NSBundle.MainBundle.LocalizedString ("Cancel", "Cancel"),
NSBundle.MainBundle.LocalizedString ("OK", "OK"));
alert.Show ();
alert.Clicked += (sender, buttonArgs) => { buttonClicked = buttonArgs.ButtonIndex; };

// Wait for a button press.
while (buttonClicked == -1)
{
NSRunLoop.Current.RunUntil(NSDate.FromTimeIntervalSinceNow (0.5));
}

if (buttonClicked == 1)
{
return true;
}
else
{
return false;
}

这似乎在iOS7中不起作用。循环将继续运行,并且 Clicked事件似乎从未触发过。有没有人提供如何执行确认警报的有效示例?

最佳答案

亚历克斯·科拉多(Alex Corrado)编写了这个美丽的示例,您可以在等待时使用它:

// Displays a UIAlertView and returns the index of the button pressed.
public static Task<int> ShowAlert (string title, string message, params string [] buttons)
{
var tcs = new TaskCompletionSource<int> ();
var alert = new UIAlertView {
Title = title,
Message = message
};
foreach (var button in buttons)
alert.AddButton (button);
alert.Clicked += (s, e) => tcs.TrySetResult (e.ButtonIndex);
alert.Show ();
return tcs.Task;
}

然后您改为:

int button = await ShowAlert ("Foo", "Bar", "Ok", "Cancel", "Maybe");

关于xamarin.ios - 是/否确认UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19120841/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com