Md Ibrahim Hassan Md Ibrahim Hassan - 2 months ago 11
iOS Question

How to find all the view controllers before my current viewcontroller in iOS?

There are different paths which a user can take to get to a particular view controller in my app. I want to know the exact path taken by the User to get to the current view controller. Any suggestion would be highly appreciated.

Answer

You can use the navigation stack in this way to get to know which viewController are there before you reach certain View controller.

Here is the Code :

for (UIViewController *vc in self.navigationController.viewControllers) {
    NSLog(@"vc desc : %@", vc.description);
}

But if you want to show a label , if the user come from a certain VC and not to show the label when come to the VC from other ViewController, Then use a boolean in the ViewController in which you need to show the label, then set the boolean as YES, while pushing from previous VC and check that boolean to show the label.

Comments