storyboardlabelviewcontrollerpopviewcontroller

How to access the second last viewcontroller in a navigation controller?


In my storyboard the User has to fill a form. After that I push a new ViewController onto the navigation stack.

If I now want to change things onto the second last ViewController I need to access it via the navigation stack (I guess). How do I gain access to it?

I use this function to get back to the last ViewController, but before I go back I wish to manipulate some labels.

- (IBAction)btnBackTapped:(id)sender {
    //magic to manipulate labels on the secound last VC ...
    [self.navigationController popViewControllerAnimated:true];
}

any ideas?


Solution

  • Here is code that will take you to your desired controller in navigation stack.

    second last controller is at index 1.

    UIViewController * VC = [self.navigationController.viewControllers objectAtIndex:1];