iOS - 不支持多次推送相同的视图控制器实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS - 不支持多次推送相同的视图控制器实例相关的知识,希望对你有一定的参考价值。
首先,是的,我知道这是一个常见的问题,已经多次讨论过。虽然我无法解决我的问题,但我想向您展示我的堆栈跟踪,看看是否有人知道这次崩溃的原因是什么。
我在整个应用程序中搜索了对pushViewController的任何调用,在推送viewController之前,我检查它是否已存在:
if (![navigationController.viewControllers containsObject: channelViewController])
{
[navigationController pushViewController: channelViewController animated:NO];
}
虽然崩溃仍然发生,但这减少了我的用户的崩溃数量。
这是堆栈跟踪:
Fatal Exception: NSInvalidArgumentException
Pushing the same view controller instance more than once is not supported (<ChannelViewController: 0x1b827360>)
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x2280010b __exceptionPreprocess
1 libobjc.A.dylib 0x21fa6e17 objc_exception_throw
2 UIKit 0x269d17e9 -[UINavigationController loadView]
3 UIKit 0x26cc2271 __54-[UINavigationController pushViewController:animated:]_block_invoke
4 UIKit 0x269d0e79 -[UINavigationController pushViewController:animated:]
5 UIKit 0x26a3e979 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:]
6 UIKit 0x26a6a31d -[_UIViewControllerTransitionContext _runAlongsideCompletions]
7 UIKit 0x26a690b1 -[_UIViewControllerTransitionContext completeTransition:]
8 UIKit 0x26a68ed9 -[UITransitionView notifyDidCompleteTransition:]
9 UIKit 0x26a68a4d -[UITransitionView _didCompleteTransition:]
10 UIKit 0x26a685ef -[UITransitionView _transitionDidStop:finished:]
11 UIKit 0x26977605 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
12 UIKit 0x269774ff -[UIViewAnimationState animationDidStop:finished:]
13 QuartzCore 0x24a3ea21 CA::Layer::run_animation_callbacks(void*)
14 libdispatch.dylib 0x22379b47 _dispatch_client_callout
15 libdispatch.dylib 0x22387ee1 _dispatch_main_queue_callback_4CF$VARIANT$mp
16 CoreFoundation 0x227c33fd __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
17 CoreFoundation 0x227c18f7 __CFRunLoopRun
18 CoreFoundation 0x22714bf9 CFRunLoopRunSpecific
19 CoreFoundation 0x227149e5 CFRunLoopRunInMode
20 GraphicsServices 0x23960ac9 GSEventRunModal
21 UIKit 0x269a4ba1 UIApplicationMain
答案
if (![navigationController.topviewcontroller containsObject: channelViewController])
{
[navigationController pushViewController: channelViewController.animated:NO];
}
试试这个,它会起作用!你得到的错误只是因为channelViewController已经在导航堆栈中。而且如果你想推动它,只需这样做:
var topview = navigationController.topviewcontroller;
topview.RemoveFromParentViewController();
[navigationController pushViewController: channelViewController animated:NO];
以上是关于iOS - 不支持多次推送相同的视图控制器实例的主要内容,如果未能解决你的问题,请参考以下文章
C# Monotouch/Xamarin.iOS - 不支持推送导航控制器