2012-03-13 65 views
3

我正在使用NavigationViewController在主视图和详细视图之间导航。现在我希望能够切换到兄弟细节视图,而无需首先显示主视图,我试图在相同方法中使用popViewController和pushViewController,或者在详细视图中使用popViewController,然后在popViewController之后使用mater的viewDidLoad中的pushViewController,但不会工作 - 视图只是返回到主视图而不切换到细节。任何想法该怎么办?通过UINavigationViewController在兄弟视图之间切换

的解决方案建议在这里,据我可以告诉不起作用: Switching Content Views Issue

回答

4

我从来没有尝试过,但是这应该工作:

// create instance of new view controller 
MyViewController *myViewController = [[MyViewController alloc] init]; 

// get current stack of viewControllers from navigation controller 
NSMutableArray *viewControllers = [[self.navigationController viewControllers] mutableCopy]; 

// replace top view controller in stack 
[viewControllers replaceObjectAtIndex:([viewControllers count] - 1) withObject:myViewController]; 

// set modified stack of view controllers in navigation controller 
[self.navigationController setViewControllers:viewControllers animated:YES]; 

the docs,您的应用程序将通过推动动画转换到新的视图控制器,然后当单击后退按钮时,它就好像您从中推送的视图控制器从不存在。 (如果你不想动画,请使用animated:NO