如何使用UINavigationController从一个视图中推送多个视图

时间:2012-06-22 09:43:57

标签: objective-c ios5 uinavigationcontroller

我使用UINavigationController编码了许多过渡应用。

这是我的过渡形象

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

    • “Main”是RootViewController。
    • 在No2和No3,if (["boo" isEqual:"foo"]){transit "A"} else if ("boo"...){transit "C"}
  5. 我可以将“主要”变为“第四”,第一过渡 像这样的

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

    但是我不能把“第二”变成“A”和“B” 我想将UIRootViewController设置为“Second” 但“第二”需要通过“A”和“C”。

    像这样的“第二”......

    SecondViewController.m

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

    我该如何编码?

    谢谢!抱歉英语不好 请帮帮我!

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

尝试使用此代码推送到控制器

 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