Kim*_* HJ 2 xamarin.ios xamarin
我正在尝试将以下代码更改为 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();
}
Run Code Online (Sandbox Code Playgroud)
我试过这就是我得到错误的地方:
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);
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。
Create在 UIAlertController 上使用静态方法:
var okCancelAlertController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2007 次 |
| 最近记录: |