How do I push many Views from one View using UINav

2019-08-15 05:07发布

问题:

I code many transition App using UINavigationController.

This is my transition image

  1. "Main"-->"Second"-->"Third"-->"Fourth"
  2. "Second"-->"A"-->"B"
  3. "Second"-->"C"
  4. "Third"-->"D"

    • "Main" is RootViewController.
    • At No2 and No3, if (["boo" isEqual:"foo"]){transit "A"} else if ("boo"...){transit "C"}.

I could make "Main" to "Forth", No.1 transition.
like this

ThirdViewController *thirdView = [[ThirdViewController alloc] init];
[self.navigationController pushViewController:thirdView animated:YES];

But I can't make "Second" to "A"and "B".
I thought to set UIRootViewController to "Second".
But "Second" needs to transit "A" and "C".

at "Second" like this...

SecondViewController.m

AViewController *aView = [[AViewController alloc] init];
[self.navigationController pushViewController:aView animated:YES];

How can I code?

Thank you! And sorry in poor English.
Please help me!

回答1:

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


回答2:

Try this code to push to a controller

 DrawImgViewcontroller *ObjImageViewController = [[DrawImgViewcontroller alloc] initWithNibName:@"DrawImgViewcontroller" bundle:nil];
    [self.navigationController  pushViewController:ObjImageViewController  animated:YES];
    [ObjImageViewController release];

and use below code to go back

[self.navigationController popViewControllerAnimated:YES];

and use this to any controller you like

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:NO];//Instead of one you can use the currect index you need