Reputation: 583
I am trying to pass some data between my first and second ViewController
.
I already instantiated the second view controller like this:
RegistrationViewController registration = new RegistrationViewController();
I set the value of the textfield to the variable email from the registration class like this:
registration.email = txtEmail.Text;
this.NavigationController.PushViewController(registration, true);
Then in the second ViewController
I use it like this:
public string email { get; set; }
txtEmail.Text = email ;
Sadly, I don't have a value in the email variable. How can I achieve successfully passing the data to the new ViewController
.
Code for changing the 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);
Upvotes: 2
Views: 3466
Reputation: 160
try this out
UIStoryboard board = UIStoryboard.FromName("Main", null);
UIViewController ctrl = (UIViewController)board.InstantiateViewController("RegistrationViewController");
ctrl.ModalTransitionStyle = UIModalTransitionStyle.CrossDissolve;
this.PresentViewController(ctrl, true, null);
Upvotes: 1
Reputation: 4903
Try something based on this :
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);
Hope it helps
Upvotes: 2