In my app, I want to remove a view controller from the stack of view controllers and then navigate to a particular view controller. Say I have A,B,C,D,E view controller stack. I wish to remove E and then go to C. I use the following code

```
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];

for (UIViewController *aViewController in allViewControllers)
    {
        if ([aViewController isKindOfClass:[noNetworkViewController class]])
        {
            [aViewController removeFromParentViewController];
        }
    }

     NSMutableArray *allbViewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];

    for (UIViewController *aViewController in allbViewControllers)
    {
        if ([aViewController isKindOfClass:[messageViewController class]])
        {
            [self.navigationController popToViewController:aViewController animated:NO];
        }
    }

```

The first for loop erases all the view controllers from the stack. Is there something I am doing wrong here. Please let me know.