我试图在我的UIViewController
中使用UIAlertController
显示消息。 使用VisualStudio的2015年CTP 5 ...如何使用UIAlertController显示来自UIViewController的提醒消息
使用的样本来自:
http://forums.xamarin.com/discussion/26404/uialertcontroller-question-for-ipad http://www.hjerpbakk.com/blog/2014/11/23/from-uialertview-to-uialertcontroller-using-xamarin-and-async-await https://gist.github.com/Sankra/622e5855f95189e13d77
基于以上的样品我有这个至今:
public partial class MyViewController : GenericViewController //inherits from UIViewController
{
.....
public async override void ViewDidLoad()
{
try
{
base.ViewDidLoad();
//other irrelevant code here
throw new Exception("Something went wrong");
}
catch (Exception ex)
{
int result = await AlertViewControllerHelper.ShowAlertDialogAsync(this, ex.StackTrace, true);
}
}
........
}
我的静态辅助等级:
public static class AlertViewControllerHelper
{
public static Task<int> ShowAlertDialogAsync(UIViewController parent, string stackTrace, bool debugMode = false)
{
var taskCompletionSource = new TaskCompletionSource<int>();
try
{
var alert = UIAlertController.Create("Error", stackTrace, UIAlertControllerStyle.ActionSheet);
if (alert.PopoverPresentationController != null)
{
alert.PopoverPresentationController.SourceView = parent.View;
alert.PopoverPresentationController.SourceRect = parent.View.Bounds;
}
alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default,
a => taskCompletionSource.SetResult(0)));
if (debugMode)
{
alert.AddAction(UIAlertAction.Create("Info", UIAlertActionStyle.Default,
a => taskCompletionSource.SetResult(1)));
}
parent.PresentViewController(alert, true, null);
}
catch (Exception ex)
{
}
return taskCompletionSource.Task;
}
运行代码后,我的错误对话不显示。 我已经完成了使用UIAlertView
但UIAlertController
到目前为止没有运气的例子(这是我的要求)提前
谢谢...