PresentModalViewController 上的应用程序崩溃
这很奇怪。在我复制目标以制作应用程序的付费版本之前,我的应用程序运行良好。当我想显示 UIViewController 时,它会被加载并显示,但我的应用程序崩溃了,并在设备日志:
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x341c2fbc objc_msgSend + 16
1 UIKit 0x3735fdfe -[UINavigationController topViewController] + 46
2 UIKit 0x37395ae4 -[UINavigationController viewDidDisappear:] + 80
3 UIKit 0x373636ae -[UIViewController _setViewAppearState:isAnimating:] + 138
4 UIKit 0x373beaea -[UIViewController _endAppearanceTransition:] + 258
5 UIKit 0x373ecec8 -[UIViewController endAppearanceTransition] + 16
6 UIKit 0x3741cf04 -[UIWindowController transitionViewDidComplete:fromView:toView:] + 1404
7 UIKit 0x373bc934 -[UITransitionView notifyDidCompleteTransition:] + 140
8 UIKit 0x373bc7b8 -[UITransitionView _didCompleteTransition:] + 896
9 UIKit 0x37336814 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 464
10 UIKit 0x3733bfb2 -[UIViewAnimationState animationDidStop:finished:] + 46
11 QuartzCore 0x34a8dba0 CA::Layer::run_animation_callbacks(void*) + 196
12 libdispatch.dylib 0x36bace86 _dispatch_main_queue_callback_4CF$VARIANT$up + 190
13 CoreFoundation 0x33f4b2d6 __CFRunLoopRun + 1262
14 CoreFoundation 0x33ece4d6 CFRunLoopRunSpecific + 294
15 CoreFoundation 0x33ece39e CFRunLoopRunInMode + 98
16 GraphicsServices 0x30752fc6 GSEventRunModal + 150
17 UIKit 0x3734f73c UIApplicationMain + 1084
18 MyApp 0x00002674 main (main.m:15)
19 MyApp 0x00002624 start + 32
我的错误在哪里?谁能帮助我吗?
This is strange.. My app worked good before I duplicated the target to make a paid version of my app.. When I want to show a UIViewController, it is loaded, and shown, but my application crashes, and gives me this error in the device log:
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x341c2fbc objc_msgSend + 16
1 UIKit 0x3735fdfe -[UINavigationController topViewController] + 46
2 UIKit 0x37395ae4 -[UINavigationController viewDidDisappear:] + 80
3 UIKit 0x373636ae -[UIViewController _setViewAppearState:isAnimating:] + 138
4 UIKit 0x373beaea -[UIViewController _endAppearanceTransition:] + 258
5 UIKit 0x373ecec8 -[UIViewController endAppearanceTransition] + 16
6 UIKit 0x3741cf04 -[UIWindowController transitionViewDidComplete:fromView:toView:] + 1404
7 UIKit 0x373bc934 -[UITransitionView notifyDidCompleteTransition:] + 140
8 UIKit 0x373bc7b8 -[UITransitionView _didCompleteTransition:] + 896
9 UIKit 0x37336814 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 464
10 UIKit 0x3733bfb2 -[UIViewAnimationState animationDidStop:finished:] + 46
11 QuartzCore 0x34a8dba0 CA::Layer::run_animation_callbacks(void*) + 196
12 libdispatch.dylib 0x36bace86 _dispatch_main_queue_callback_4CF$VARIANT$up + 190
13 CoreFoundation 0x33f4b2d6 __CFRunLoopRun + 1262
14 CoreFoundation 0x33ece4d6 CFRunLoopRunSpecific + 294
15 CoreFoundation 0x33ece39e CFRunLoopRunInMode + 98
16 GraphicsServices 0x30752fc6 GSEventRunModal + 150
17 UIKit 0x3734f73c UIApplicationMain + 1084
18 MyApp 0x00002674 main (main.m:15)
19 MyApp 0x00002624 start + 32
Where is my error? Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来就像一个僵尸对象访问,只是从表面上看。不确定为什么单独欺骗目标会导致这种情况,但您是否尝试过在模拟器中使用 Zombies 工具分析您的应用程序?
编辑:
是的。好吧,现在你知道发生了什么了。同样,我很难想象仅仅复制一个目标会如何导致这种情况发生。应该保留的对象没有被保留。造成这种情况的原因有很多,但一个潜在的原因是 @property 应该被声明为
retain
或copy
,但却被声明为assign
。僵尸工具可以进一步帮助您:在该错误消息旁边,应该有一个圆圈中的小箭头。如果您单击它,它应该会带您进入详细视图,其中显示该对象在其生命周期中保留和释放的所有内容。这可能有帮助,也可能没有帮助。如果问题是某些东西“过度释放”了该对象,您也许可以从列表中看出,但更可能的问题是应该保留它的东西却没有,并且不会显示在列表中。
该列表中可能有用的是查看谁创建了该对象,因为通常这将是该对象的逻辑“所有者”(或者它将把它传递给逻辑所有者)。我会仔细检查我的项目,并考虑相关对象的预期所有权。谁应该拥有这个对象?他们为什么不保留它?
如果您仍不了解 Cocoa 内存管理,我建议您阅读 Apple 的指南:高级内存管理编程指南 修复僵尸对象访问是 Objective-C 开发人员的必经之路。坚持使用该平台,您无疑将有很多机会磨练您的技术。
您还可以考虑使用自动引用计数 (ARC)。它的目的是让你不必考虑这些东西,而且实际上效果非常好。
编辑2:
我突然想到:您是否有可能在原始目标中使用ARC,并且当您复制目标时,该设置以某种方式被关闭?这肯定能解释它。
This looks like a zombie object access, just on it's face. Not sure why duping the target alone would cause this, but have you tried profiling your app with the Zombies instrument in the simulator?
EDIT:
Yup. OK, now you know what's happening. Again, it's hard for me to imagine how merely duplicating a target could cause this to happen. An object that should be being retained is not being retained. There are any number of causes for this, but one potential cause is a @property that should be declared
retain
orcopy
, but is declaredassign
. The Zombies instrument can help you out further:Next to that error message, there should be a little arrow in a circle. If you click that it should take you to a detail view that shows you all the things that retained and released that object during it's life. This might be helpful, it might not. If the problem is that something is "overreleasing" the object, you might be able to tell from the list, but more likely the problem is that something that should retain it, isn't, and that won't show up on the list.
What might be helpful in that list is to see who created the object, because typically that will be the logical "owner" of the object (or it will pass it into the logical owner). I would go through my project, and think about the intended ownership of the object in question. Who should own this object? Why aren't they retaining it?
If you're still coming up to speed with Cocoa memory management, I recommend reading Apple's guide: Advanced Memory Management Programming Guide Fixing zombie object accesses is a rite of passage for Objective-C developers. Stick with the platform and you'll undoubtedly have many opportunities to hone your technique.
You might also consider using Automatic Reference Counting (ARC). It's meant to make it so you don't have to think about this stuff, and actually works pretty darn well.
EDIT 2:
Just occurred to me: Is it possible you were using ARC in the original target and when you duplicated the target, that setting somehow got turned off? That would certainly explain it.