如何重置UINavigationController? [英] How do I reset a UINavigationController?

查看:223
本文介绍了如何重置UINavigationController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了涉及UINavigationController的问题。



我有一个应用程序,它有三个视图控制器,我正在使用导航控制器推送和弹出功能切换。



问题是:
我站在第三个视图控制器中并调用

[self.navigationController popToRootViewControllerAnimated:YES ]。

这将我带到第一个视图控制器(这正是我想要的)但是当我尝试导航到第二个视图控制器时,由于某种原因,我最终会进入第三个视图控制器。



你有什么办法可以重置导航控制器,或者我这样做是错误的吗?



这是代码我正在使用推送和弹出导航控制器:



当用户决定启动摄像机时,在根视图控制器中调用以下代码。 / strong>

  if(self.cameraViewController == nil)
{
CollageCameraViewController * camView = [ [CollageCameraViewController alloc] init]; // WithNibName:nil bundle:[NSBundle mainBundle]];
self.cameraViewController = camView;
[camView发布];

}
[self.navigationController pushViewController:self.cameraViewController animated:NO];

在用户拍摄照片后,从CollageCameraViewController(第二个)调用以下代码:

  if(self.renderView == nil)
{
CollageRenderViewController * renderViewController = [[CollageRenderViewController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
self.renderView = renderViewController;
[renderViewController release];
}
[self.navigationController pushViewController:self.renderView animated:YES];

当用户决定返回main(root)时,从CollageRenderViewController调用以下代码)查看:

  [self.navigationController popToRootViewControllerAnimated:YES]; 

现在,如果我再次尝试推送CollageCameraViewController,我最终会使用CollageRenderViewController,为什么会这样? / p>

干杯,
Andreas

解决方案

我有几个风投在我移动到真正的主屏幕之前,在我的堆栈中作为设置屏幕。



我得到了这样的工作:

  HomeViewController * hvc = [[HomeViewController alloc] init]; 
[self.navigationController pushViewController:hvc animated:YES];
self.navigationController.viewControllers = [[NSArray alloc] initWithObjects:hvc,nil];

我按下HomeViewController,然后重写堆栈只有主屏幕。


I have a problem involving the UINavigationController.

I have a application that have three view controllers that I'm switching between using the navigation controllers push and pop functionality.

The problem is this: I stand in the third view controller and makes a call to
[self.navigationController popToRootViewControllerAnimated:YES];
this brings me to the first view controller (which is exactly what I want) but when I then try to navigate to the second view controller I end up in the third for some reason.

Is there any way you can reset the navigation controller, or am I doing this the wrong way?

Here is the code that I'm using to push and pop the navigation controller:

The following code is called in the root view controller when the user decides to launch the camera.

if(self.cameraViewController == nil)
{
        CollageCameraViewController *camView = [[CollageCameraViewController alloc] init];//WithNibName:nil bundle:[NSBundle mainBundle]];
        self.cameraViewController = camView;
        [camView release];

}
[self.navigationController pushViewController:self.cameraViewController animated:NO];

The following code is called from CollageCameraViewController (second) after the user has taken his fotos:

if(self.renderView == nil)
{
    CollageRenderViewController *renderViewController = [[CollageRenderViewController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
    self.renderView = renderViewController;
    [renderViewController release];
}
[self.navigationController pushViewController:self.renderView animated:YES];

The following code is called from CollageRenderViewController when the user decides to go back to main (root) view:

[self.navigationController popToRootViewControllerAnimated:YES];

Now, if I try to push CollageCameraViewController again I end up in CollageRenderViewController instead, why is that?

Cheers, Andreas

解决方案

I have several VCs in my stack as set-up screens before I move to the true home screen.

I got mine to work like this:

HomeViewController *hvc = [[HomeViewController alloc] init];
[self.navigationController pushViewController:hvc animated:YES];
self.navigationController.viewControllers = [[NSArray alloc] initWithObjects:hvc, nil];

I push the HomeViewController and then rewrite the stack to only have the home screen.

这篇关于如何重置UINavigationController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆