为Xamarin重定向UIViewController
本文关键字:UIViewController 重定向 Xamarin | 更新日期: 2023-09-27 18:14:15
我正在创建一个方法来显示一个对话框,这是我目前所做的:
public void ShowDialog(String title = "",String msg = "")
{
this.alert.Title = title;
this.alert.AddButton("Ok");
this.alert.Message = msg;
this.alert.Show();
}
这个位于一个公共类,所以它可以与其他类一起使用,
我想添加一个参数,以便在按下"确定"按钮后,它将重定向到某个UIViewController,我尝试这样做:
public void ShowDialog(String title = "",String msg = "", UIViewController view = null)
{
this.alert.Title = title;
this.alert.AddButton("Ok");
this.alert.Message = msg;
this.alert.Clicked += (object sender1, UIButtonEventArgs e) => {
if(e.ButtonIndex.ToString () == "0" && view != null){
NavigationController.PushViewController(view, true);
}
};
this.alert.Show();
}
但显然这是不工作,我错过了什么?或者这是可能的吗?
Thanks in advance.
如何命名
Common common = new Common();
common.ShowDialog("Error","Invalid Process!!", new HomeScreen());
最后我这样做了:
public void ShowDialog(String title = "",String msg = "", UIViewController instance = null, UIViewController redirectTo = null)
{
this.alert.Title = title;
this.alert.AddButton("Ok");
this.alert.Message = msg;
this.alert.Clicked += (object sender1, UIButtonEventArgs e) => {
if(e.ButtonIndex.ToString () == "0" && instance != null && redirectTo != null){
instance.NavigationController.PushViewController(redirectTo, true);
}
};
this.alert.Show();
}
然后这样调用:
Common common = new Common();
common.ShowDialog("Error","Invalid Process!", this, new HomeScreen());