2
votes

I am making an iPad app which has many view controllers with a non-linear flow. I used navigation controller at first but after some time it became difficult to manage the stack (to push and pop view). If i just go with pushing the view at every navigation, eventually the stack will become too heavy to be managed and is undesirable.

So i came across a way to replace the rootviewcontroller every time i want to make a navigation

Here's the code for it

twoViewController *twoVC = [[twoViewController alloc] init] ;
[self.navigationController setViewControllers: [NSArray arrayWithObject: twoVC]  animated: YES];

I am writing this code in Firstviewcontroller. twoViewController is the viewcontroller i want to replace with the rootviewcontroller.

Problem: it is navigation but now the twoViewController is coming totally black.

Please help...

Note- i am using using storyboard

1
didn't understand completely,but navigation controller is the simplest way to use viewControllers.You can easily to push to someController and pop to particular ViewController. - Prince Kumar Sharma
actually, in my application, the flow is not defined,i.e, u can go to any viewcontroller from any other. this is causing the views to push on the stack continuously, and eventually the stack to become so heavy for the app to manage. - iOS_DEV
that is what I am saying push only those views that is not in the stack.If it is in the controllers stack then pop to that View.This will make it easy. - Prince Kumar Sharma

1 Answers

0
votes

If you are facing problem to pop to particular View Controller then use following method to search out and pop to Particular ViewController.

-(IBAction)mainMenu:(id)sender
{
    for (int m=0; m<([self.navigationController.viewControllers count]); m++)
    {
        if ([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[MainMenuViewController class]]) {
            MainMenuViewController *mainMenu=[self.navigationController.viewControllers objectAtIndex:m];
            [self.navigationController popToViewController:mainMenu animated:YES];
        }
    }
}