0

I am new to this Ios application. I have a 9 view and some time user can skip some view. eg. user can jump to 3 rd view to 5th view. I want to go back to the previous view ( including the skipped view ) I will explain in detail

i have jumped to 3rd view to 5th view. From 5th view there is a back button , when click on that button i need to jump back to 4th view.

currently i have used

 HealtghCareResponsibilityViewController *objPri = [viewsArray objectAtIndex:4];



[objPri passArrayFromEndDisclosure:self.arrayToPass];


[self.navigationController popToViewController:objPri animated:YES];

But i know that 4th view was skipped, so 4th index is not in objectAtIndex.

But i need to go back to 4th index, Is there is any way ?

user1878525
  • 13
  • 1
  • 5

2 Answers2

1
for (UIViewController *controller in self.navigationController.viewControllers)
        {
            if ([controller isKindOfClass:[nameOfYourViewControllerYouWantToNavigate class]])
            {
                [self.navigationController popToViewController:controller animated:YES];

                break;
            }
        }
KDeogharkar
  • 10,939
  • 7
  • 51
  • 95
0

You can do:

if ([[self.navigationController.viewControllers containsObject:objPri]) {
    [self.navigationController popToViewController:objPri animated:YES];
} else {
    [self.navigationController pushViewController:objPri animated:YES];
}

So if it was previously shown you go back to it and if not you add it.


Alternate:

Replace the view controllers just so you can pop:

NSArray *viewControllers = @[ objPri, self.navigationController.topVviewController ];
self.navigationController.viewControllers = viewControllers];
[self.navigationController popViewControllerAnimated:YES];
Wain
  • 118,658
  • 15
  • 128
  • 151
  • Tks, suppose if i want to go back to the 2nd view from 5 th view ) 2nd was skipped). Then ? Please reply this too – user1878525 Jul 17 '13 at 07:26
  • It's exactly the same situation, you just change the object referred to by the `objPri` reference. – Wain Jul 17 '13 at 07:31
  • Tks, it's working. But i have used a special type of disply, ir back view is displays as in a manner screen is scrolled to back. But with your code it's moved to forward. Ie from 5 th view we ffel that moved to 3 rd view ( 5th is moved back and over write 3 i need 5th moved to right ie feel like to back to third) i think you can understand it please reply this too – user1878525 Jul 17 '13 at 07:34
  • Pls reply, we have stuck...Please – user1878525 Jul 17 '13 at 07:37