UIAlertView已弃用的Xamarin iOS

UIAlertView已弃用的Xamarin iOS,xamarin,xamarin.ios,Xamarin,Xamarin.ios,我正在尝试将以下代码更改为UIAlertController,但我收到一个错误,即非可开票成员“UIAlertController”不能像方法一样使用 这是AppDelegate.cs中的原始代码 private void remoteNotificationPayload(NSDictionary userInfo) { var aps_d = userInfo["aps"] as NSDictionary; var alert_d = aps_d["a

我正在尝试将以下代码更改为UIAlertController,但我收到一个错误,即非可开票成员“UIAlertController”不能像方法一样使用

这是AppDelegate.cs中的原始代码

private void remoteNotificationPayload(NSDictionary userInfo)
    {
        var aps_d = userInfo["aps"] as NSDictionary;
        var alert_d = aps_d["alert"] as NSDictionary;
        var body = alert_d["body"] as NSString;
        var title = alert_d["title"] as NSString;

        this.showAlert(title, body);
    }

private void showAlert(string title, string message)
{
  var alert = new UIAlertView(title ?? "Title", message ?? "Message", null, "Cancel", "OK");
  alert.Show();
}
我尝试了这个,这就是我得到错误的地方:

private void showAlert(string title, string message)
{
 var okCancelAlertController = UIAlertController(title ?? "Title", message ?? "Message", preferredStyle: UIAlertControllerStyle.Alert);

 okCancelAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, alert => Console.WriteLine("Okay was clicked")));

 okCancelAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, alert => Console.WriteLine("Cancel was clicked")));
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(okCancelAlertController, true, null);
}
感谢您的帮助。

在UIAlertController上使用静态创建方法:

var okCancelAlertController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
在UIAlertController上使用静态创建方法:

var okCancelAlertController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

谢谢,我不敢相信我忘了创作。谢谢,我不敢相信我忘了创作。