不支持多次推送视图控制器?
每当我尝试像这样切换视图时,我都会收到以下错误:
-(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当将 2 个视图推入堆栈时,请尝试调用:
并且
如果您尝试将两个视图上的动画:字段设置为 YES 来推入多个视图,那么您会混淆堆栈。一次仅对一个视图进行动画处理。
When pushing 2 views onto the stack, try to call:
and
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.
仅供参考,如果您调用 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.
推送前检查此条件
Check this condition before push