gpt4 book ai didi

c# - 如何在 Xamarin 中的 View Controller 之间传递数据

转载 作者:太空宇宙 更新时间:2023-11-03 15:09:18 24 4
gpt4 key购买 nike

我试图在我的第一个和第二个 ViewController 之间传递一些数据。我已经像这样实例化了第二个 View Controller :

RegistrationViewController registration = new RegistrationViewController();

我将文本字段的值设置为来自注册类的变量电子邮件,如下所示:

registration.email = txtEmail.Text; 
this.NavigationController.PushViewController(registration, true);

然后在第二个 ViewController 中我这样使用它:

public string email { get; set; }
txtEmail.Text = email ;

遗憾的是,我在 email 变量中没有值。我怎样才能成功地将数据传递给新的 ViewController

改变 Controller 的代码:

 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);

希望对你有帮助

关于c# - 如何在 Xamarin 中的 View Controller 之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41897666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com