我收到了这个崩溃报告,但我不知道如何调试它。
Fatal Exception NSInvalidArgumentException
Can't add self as subview
0 ... CoreFoundation __exceptionPreprocess + 130
1 libobjc.A.dylib objc_exception_throw + 38
2 CoreFoundation -[NSException initWithCoder:]
3 UIKit -[UIView(Internal) _addSubview:positioned:relativeTo:] + 110
4 UIKit -[UIView(Hierarchy) addSubview:] + 30
5 UIKit __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 1196
6 UIKit +[UIView(Animation) performWithoutAnimation:] + 72
7 UIKit -[_UINavigationParallaxTransition animateTransition:] + 732
8 UIKit -[UINavigationController _startCustomTransition:] + 2616
9 UIKit -[UINavigationController _startDeferredTransitionIfNeeded:] + 418
10 UIKit -[UINavigationController __viewWillLayoutSubviews] + 44
11 UIKit -[UILayoutContainerView layoutSubviews] + 184
12 UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 346
13 QuartzCore -[CALayer layoutSublayers] + 142
14 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) + 350
15 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
16 QuartzCore CA::Context::commit_transaction(CA::Transaction*) + 228
17 QuartzCore CA::Transaction::commit() + 314
18 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
iOS 版本为 7.0.3。 有人遇到过这种奇怪的崩溃吗?
更新:
我不知道我的代码在哪里导致了这个崩溃,所以我不能在这里发布代码,对不起。
第二次更新
请看下面的答案。
最佳答案
我根据我最近调试的类似的东西进行推测...... 如果您使用 Animated:YES 推送(或弹出) View Controller ,它不会立即完成,如果您在动画完成之前再次推送或弹出,则会发生坏事。您可以通过暂时将 Push 和 Pop 操作更改为 Animated:NO(以便它们同步完成)并查看是否消除了崩溃来轻松测试是否确实如此。 如果这确实是您的问题并且您希望重新打开动画,那么正确的策略是实现 UINavigationControllerDelegate 协议(protocol)。 其中包括如下方法,在动画完成后调用:
navigationController:didShowViewController:animated:
基本上,您希望根据需要将一些代码移动到此方法中,以确保在动画完成并且堆栈准备好进行更多更改之前,不会发生可能导致 NavigationController 堆栈更改的其他操作。
https://stackoverflow.com/questions/19560198/