Search code examples
iosseguepoptoviewcontroller

Assigning a variable during [self.navigationController popToRootViewControllerAnimated:YES];


I am looking for a way to assign ivar when [self.navigationController popToRootViewControllerAnimated:YES]; is called, similarly to how you can set values when a segue is called:

if ([segue.identifier isEqualToString:@"login"]) {
    [sender resignFirstResponder];
    HomeController * home = (HomeController *)segue.destinationViewController;
    home.personHome = self.person;

}

where I am assigning an objects variables. The current architecture uses [self.navigationController popToRootViewControllerAnimated:YES];

When the application loads the HomeController is the first view but in its view did Load methods it calls [self performSegueWithIdentifier:@"login" sender:self]; to go to the login screen. Successfully login in pops back.

Advice and direction is greatly appreciated.


Solution

  • This worked:

    HomeController *myController = (HomeController *)[self.navigationController.viewControllers objectAtIndex:0];
    myController.personHome =self.person ;
    [self.navigationController popToViewController:myController animated:YES];