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.
- 1you can maintain a stack of ViewControllers in a singelton class.Umair Afzal– Umair Afzal2016-09-29 11:35:43 +00:00Commented Sep 29, 2016 at 11:35
4 Answers
I had similar issue in one of my projects and I created a singleton class which maintains a stack of ViewControllers. Each ViewController is responsible for pushing and popping itself from the stack. Thus, we queried stack whenever we wanted to have flow that user followed.
It worked pretty fine for us.
Comments
You can check your controller by comparing it, Put your desired class instead of "XYZViewController"
for (UIViewController * aController in self.navigationController.viewControllers) { if (aController isKindOfClass:[XYZViewController class]) { //You can do your work here } } 4 Comments
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
In the current view controller's viewDidAppear(), viewWillAppear() or the viewDidLoad() method use the following code. I have used it my viewDidLoad() method.
for (int i=0;i<[self.navigationController.viewControllers count];i++) { NSLog(@"%d>>>>>>>>>%@",[self.navigationController.viewControllers objectAtIndex:i]); }