如何在Xamarin中的视图控制器之间传递数据
我试图在我的第一个和第二个ViewController
之间传递一些数据。 我已经像这样实例化了第二个视图控制器:
RegistrationViewController registration = new RegistrationViewController();
我将textfield的值设置为来自注册类的变量email,如下所示:
registration.email = txtEmail.Text; this.NavigationController.PushViewController(registration, true);
然后在第二个ViewController
我使用它像这样:
public string email { get; set; } txtEmail.Text = email ;
可悲的是,我在电子邮件变量中没有值。 如何成功将数据传递给新的ViewController
。
更改控制器的代码:
registration.email = txtEmail.Text; string password = txtPassword.Text; RegistrationViewController controller = this.Storyboard.InstantiateViewController("RegistrationViewController") as RegistrationViewController; this.NavigationController.PushViewController(registration, true); this.NavigationController.PushViewController(controller, true);
尝试基于此的东西:
SecondViewController controller = this.Storyboard.InstantiateViewController("SecondViewController") as SecondViewController; //Here you pass the data from the registerViewController to the secondViewController controller.email = registration.email; this.NavigationController.PushViewController(registration, true);
希望能帮助到你