self.navigationController popToRootViewControllerAnimated:YES不弹回root [英] self.navigationController popToRootViewControllerAnimated:YES do not pop back to the root

查看:152
本文介绍了self.navigationController popToRootViewControllerAnimated:YES不弹回root的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当点击顶部栏上的后退按钮时,我有这行代码回弹到根菜单:

I have this line of code to pop back to the root menu when clicking the "back" button on the top bar:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

到目前为止我没有遇到任何问题,我仍然使用IOS 5.1目标。

I have had no problem with this until now, i still use IOS 5.1 as target.

当我现在运行此代码(XCODE 5)时,我收到以下消息:

As i run this code now (XCODE 5) i get the following message:

Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

...它似乎只是将顶部栏中的文字弹回到根目录(菜单)而显示器只弹出一个级别。由于这一直有效,我有点困惑,想要一些建议如何解决这个问题。视图控制器是我执行此代码是一个普通的ViewController。

...and it only seems to pop the text in the top bar back to the root (Menu) while the display only pop's back one level. As this has always worked i am a bit puzzled and would like some advice how to solve this. The View Controller were i execute this code is a normal ViewController.

我使用 [self performSegueWithIdentifier:@xxxxxsender:self]; 推送ViewControllers。

I use [self performSegueWithIdentifier:@"xxxxx" sender:self];to push the ViewControllers.

仅用于测试我使用此代码:

Just for testing i used this code:

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

...它确实弹出VC然后直接弹出到没有消息的rootVC ???

...and it did pop the VC and then directly pop'ed back to the rootVC without the messages???

这是结构,它来自绿色VC我有问题回到第一个VC。同样,我在xcode5之前没有遇到过这个问题:

Here is the structure, it is from the green VC i have problem going back to the first VC. Again, i have not had this problem prior to xcode5:

推荐答案

好的我刚注意到当用户推回时,你正试图弹出到root,但是这里发生了什么:

Ok I just noticed you are trying to pop to root, when the user pushes back, but here is what is happening:

操作系统正试图用动画推送到之前的viewController,同时,你正在启动第二次转换并询问它弹出到根视图控制器。

The OS is trying to push to the previous viewController with an animation and in the same moment, you are initiating a second transition and ask it to pop to the root view controller.

最简单的方法是使用自定义按钮替换系统的后退按钮,该按钮将使用您自己的IBAction,然后您将弹出到rootViewController:

The easiest approach would to replace the system's back button with a custom button that will use your own IBAction and you will then pop to the rootViewController:

首先隐藏后退按钮:

self.navigationItem.hidesBackButton = YES;

然后创建自己的自定义后退按钮:

and then create your own custom back Button:

UIBarButtonItem *backBtn =[[UIBarButtonItem alloc]initWithTitle:@"back" style:UIBarButtonItemStyleDone target:self action:@selector(popToRoot:)];
self.navigationItem.leftBarButtonItem=backBtn;

最后你弹出RootViewController:

Finally you pop to the RootViewController:

- (IBAction)popToRoot:(UIBarButtonItem*)sender {
   [self.navigationController popToRootViewControllerAnimated:YES];
}

请记住删除 [self.navigationController popToRootViewControllerAnimated:是]; 来自 ViewWillDisappear 委托。

这篇关于self.navigationController popToRootViewControllerAnimated:YES不弹回root的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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