我如何使许多浏览使用UINavigationController的一个视图(How do I pus

2019-10-16 21:35发布

我很多代码转换应用程序中使用UINavigationController

这是我的过渡图像

  1. “主” - > “二” - > “三” - > “第四”
  2. “秒” - > “A” - > “B”
  3. “秒” - > “C”
  4. “第三” - > “d”

    • “主要”是RootViewController的。
    • 在NO 2和NO, if (["boo" isEqual:"foo"]){transit "A"} else if ("boo"...){transit "C"}

我可以做“主”到“第四”,1号过渡。
像这样

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

但我不能让“二”到“A”和“B”。
我认为UIRootViewController设定为“秒”。
但是,“二”需要过境“A”和“C”。

在“第二”这样的...

SecondViewController.m

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

我该如何编写?

谢谢! 而在英语不好对不起。
请帮我!

Answer 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];    


Answer 2:

试试这个代码推到控制器

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

并使用下面的代码回去

[self.navigationController popViewControllerAnimated:YES];

并用它来你喜欢的任何控制器

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


文章来源: How do I push many Views from one View using UINavigationController