不支持多次推送视图控制器?

发布于 2024-12-04 04:41:25 字数 858 浏览 2 评论 0原文

每当我尝试像这样切换视图时,我都会收到以下错误:

-(void)changeView1ToView4 {
    [self.navigationController1 pushViewController:view4 animated:YES];
}

当应用程序首次加载且用户直接进入此视图时,不会发生这种情况。仅当我转到其他视图之一,返回主菜单,然后尝试转到此视图时,才会发生此崩溃。

另外,如果您还不确定,我正在使用 UINavigationController。另外,此代码位于应用程序委托中,我从具有父视图的视图控制器调用它,因此我使用 .reference 来调用它,如下所示:

[self.reference changeView1ToView4];

有没有真正的方法可以解决此问题?

谢谢!

编辑1:

[self.navigationController1 pushViewController:view4 animated:NO];
[self.navigationController1 pushViewController:view4 animated:YES];

I tried that and got this crash message in the console:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported (<View2: 0x18d540>)'

I am getting the following error whenever I try to switch views like this:

-(void)changeView1ToView4 {
    [self.navigationController1 pushViewController:view4 animated:YES];
}

This doesn't happen when the app first loads and user goes directly to this view. This crash only happens when I go to one of my other views, come back to the main menu, and then try to go to this view.

Also if you weren't sure already, I am using a UINavigationController. Also this code is in the app delegate and I am calling it from a view controller which has a parent view so I am using a .reference to call it like this:

[self.reference changeView1ToView4];

Is there any real way to fix this?

Thanks!

Edit1:

[self.navigationController1 pushViewController:view4 animated:NO];
[self.navigationController1 pushViewController:view4 animated:YES];

I tried that and got this crash message in the console:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported (<View2: 0x18d540>)'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寒冷纷飞旳雪 2024-12-11 04:41:25

当将 2 个视图推入堆栈时,请尝试调用:

[self.navigationController1 pushViewController:view4 animated:YES];

并且

[self.navigationController1 pushViewController://secondviewcontrollername// animated:NO];

如果您尝试将两个视图上的动画:字段设置为 YES 来推入多个视图,那么您会混淆堆栈。一次仅对一个视图进行动画处理。

When pushing 2 views onto the stack, try to call:

[self.navigationController1 pushViewController:view4 animated:YES];

and

[self.navigationController1 pushViewController://secondviewcontrollername// animated:NO];

If you try to push more than one view with the animated: field set to YES on both, then you confuse the stack. Only animate one view at a time.

半透明的墙 2024-12-11 04:41:25

仅供参考,如果您调用 setViewControllers:animated: ,则无需随后调用 pushViewController: ,否则您将收到“不支持多次推送同一视图控制器实例”崩溃。

just an FYI, if you call setViewControllers:animated: there's no need to call pushViewController: afterwards, else you'll get the "Pushing the same view controller instance more than once is not supported" crash.

单身狗的梦 2024-12-11 04:41:25
            @try {
               [self.navController pushViewController:viewController animated:NO];
            } @catch (NSException * e) {
                NSLog(@"Exception: %@", e);
                 [self.navigationController popToViewController:viewController animated:NO];
            } @finally {
                //NSLog(@"finally");
            }
            @try {
               [self.navController pushViewController:viewController animated:NO];
            } @catch (NSException * e) {
                NSLog(@"Exception: %@", e);
                 [self.navigationController popToViewController:viewController animated:NO];
            } @finally {
                //NSLog(@"finally");
            }
陪我终i 2024-12-11 04:41:25

推送前检查此条件

if (![[self.navigationController topViewController] isKindOfClass:[YOURCONTROLLER class]])
    [self.navigationController pushViewController:YOURCONTROLLER animated:YES];

Check this condition before push

if (![[self.navigationController topViewController] isKindOfClass:[YOURCONTROLLER class]])
    [self.navigationController pushViewController:YOURCONTROLLER animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文