0

I have created a module in which i have 5 classes in this i need to perform a task like

vc1->vc2->vc3

now from vc3 i used to push vc4 from the reference of a base class. base class is a class on which vc1 controller's is added as a subview.

and now i need to pop from vc4 to vc3.

Shekhar Gupta
  • 6,206
  • 3
  • 30
  • 50
Divyam shukla
  • 2,038
  • 14
  • 18

2 Answers2

0
NSInteger index = 0;
for (UIViewController *view in self.navigationController.viewControllers) {
  if([view.nibName isEqualToString:@"YourViewController"])//put any `XIB name` where u want to navigate 
  break;
index = index + 1;
}
 //[[self navigationController] pushViewController:[[self.navigationController viewControllers] objectAtIndex:index] animated:YES];

[[self navigationController] popToViewController:[[self.navigationController viewControllers] objectAtIndex:index] animated:YES];    
Rinju Jain
  • 1,694
  • 1
  • 14
  • 23
  • it will not work please try it by your self i have already done that as you will not get the viewcontroller in the navigation stack coz there will be 2 navigation stacks – Divyam shukla Jul 24 '13 at 08:45
0
NSArray *array = [self.navigationController viewControllers];

[self.navigationController popToViewController:[array objectAtIndex:2] animated:YES];

Get the index of the view controller you want to pop to.

Please refer to these links :-

Can i pop to Specific ViewController?

pop a specific view controller

Community
  • 1
  • 1
IronManGill
  • 7,222
  • 2
  • 31
  • 52