Search code examples
iosios4uinavigationcontroller

How to go 2 views back in navigation based application


I have created a View based based application of 4 views. By using navigation controller I am changing the view. In my 3rd view one button is there. If I click on that button the app should come to the first view (2 views back).

I have used

[self.navigationController popViewControllerAnimated:YES]; 
[self.navigationController popViewControllerAnimated:YES];  

This is not working. It's going to the previous page only.


Solution

  • Try out this, and make change according your specification

    -(void)goToMainCategoryView;
    {
    id object = nil;
    
    for (UIViewController *viewControl in self.navigationController.viewControllers)
    {
        if(viewControl.view.tag == 0)
        {
            object = viewControl;
        }
    }
    [self.navigationController popToViewController:object animated:YES];
    }