视图控制器在发布后收到发送给它的消息,导致崩溃

Posted

技术标签:

【中文标题】视图控制器在发布后收到发送给它的消息,导致崩溃【英文标题】:View Controller getting a message sent to it after release, causes a crash 【发布时间】:2013-02-18 00:10:19 【问题描述】:

我有一个设置,我在其中呈现 UIPickerViewController(模态),然后将更多控制器推入堆栈以进行图像编辑。如果我点击后退按钮并进入根视图控制器,然后点击另一个选项卡,应用程序就会崩溃。

这是崩溃消息:

-[PostPhotoViewController respondsToSelector:]: message sent to deallocated instance 0x19b16a60

我运行了 Zombies 工具,看起来堆栈上的最后一个视图控制器 (PostPhotoViewController) 正在接收发送给它的消息,即使它已被释放。这在 ios5 和 6 上都发生了,所以我没有做任何手动释放/保留。

我已将所有出口设置为 nil PostPhotoVC 并取消订阅所有通知。该消息似乎来自标签栏控制器。

不知道如何阻止它,有什么想法吗?

这是僵尸读数:

#   Address Category    Event Type  RefCt   Timestamp   Size    Responsible Library Responsible Caller
0   0x1b730790  PostPhotoViewController Malloc  1   00:19.248.903   256 UIKit   -[UIClassSwapper initWithCoder:]
1   0x1b730790  PostPhotoViewController Retain  2   00:19.248.948   0   UIKit   UINibDecoderDecodeObjectForValue
2   0x1b730790  PostPhotoViewController Retain  3   00:19.248.998   0   UIKit   -[UIRuntimeConnection initWithCoder:]
3   0x1b730790  PostPhotoViewController Retain  4   00:19.249.004   0   UIKit   -[UIRuntimeConnection initWithCoder:]
4   0x1b730790  PostPhotoViewController Retain  5   00:19.249.025   0   UIKit   -[UIRuntimeConnection initWithCoder:]
5   0x1b730790  PostPhotoViewController Retain  6   00:19.249.030   0   UIKit   -[UIRuntimeConnection initWithCoder:]
6   0x1b730790  PostPhotoViewController Retain  7   00:19.249.067   0   UIKit   UINibDecoderDecodeObjectForValue
7   0x1b730790  PostPhotoViewController Retain  8   00:19.249.080   0   UIKit   UINibDecoderDecodeObjectForValue
8   0x1b730790  PostPhotoViewController Retain  9   00:19.249.648   0   UIKit   -[UIStoryboardScene setSceneViewController:]
9   0x1b730790  PostPhotoViewController Retain  10  00:19.249.759   0   UIKit   -[UINib instantiateWithOwner:options:]
10  0x1b730790  PostPhotoViewController Release 9   00:19.249.849   0   UIKit   -[UINibDecoder finishDecoding]
11  0x1b730790  PostPhotoViewController Release 8   00:19.249.884   0   UIKit   -[UINibDecoder finishDecoding]
12  0x1b730790  PostPhotoViewController Release 7   00:19.249.897   0   UIKit   -[UINibDecoder finishDecoding]
13  0x1b730790  PostPhotoViewController Release 6   00:19.249.900   0   UIKit   -[UINibDecoder finishDecoding]
14  0x1b730790  PostPhotoViewController Release 5   00:19.249.921   0   UIKit   -[UIRuntimeConnection dealloc]
15  0x1b730790  PostPhotoViewController Release 4   00:19.249.930   0   UIKit   -[UIRuntimeConnection dealloc]
16  0x1b730790  PostPhotoViewController Release 3   00:19.249.936   0   UIKit   -[UIRuntimeConnection dealloc]
17  0x1b730790  PostPhotoViewController Release 2   00:19.249.946   0   UIKit   -[UIRuntimeConnection dealloc]
18  0x1b730790  PostPhotoViewController Retain  3   00:19.249.998   0   UIKit   -[UIStoryboardSegue initWithIdentifier:source:destination:]
19  0x1b730790  PostPhotoViewController Retain  4   00:19.250.010   0   V Nation    -[ImageEditViewController prepareForSegue:sender:]
20  0x1b730790  PostPhotoViewController Release 3   00:19.250.018   0   V Nation    -[ImageEditViewController prepareForSegue:sender:]
21  0x1b730790  PostPhotoViewController Retain  4   00:19.250.045   0   UIKit   -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:]
22  0x1b730790  PostPhotoViewController Release 3   00:19.254.033   0   UIKit   -[UIStoryboardSegue dealloc]
23  0x1b730790  PostPhotoViewController Release 2   00:19.254.037   0   UIKit   _UIApplicationHandleEvent
24  0x1b730790  PostPhotoViewController Release 1   00:19.254.047   0   UIKit   -[UIStoryboardScene dealloc]
25  0x1b730790  PostPhotoViewController Retain  2   00:19.254.119   0   UIKit   -[UINavigationController topViewController]
26  0x1b730790  PostPhotoViewController Autorelease     00:19.254.124   0   UIKit   -[UINavigationController topViewController]
27  0x1b730790  PostPhotoViewController Retain  3   00:19.254.935   0   UIKit   -[UINib instantiateWithOwner:options:]
28  0x1b730790  PostPhotoViewController Retain  4   00:19.254.944   0   UIKit   +[UIProxyObject addMappingFromIdentifier:toObject:forCoder:]
29  0x1b730790  PostPhotoViewController Retain  5   00:19.254.950   0   UIKit   -[UINib instantiateWithOwner:options:]
30  0x1b730790  PostPhotoViewController Retain  6   00:19.254.957   0   UIKit   +[UIProxyObject addMappingFromIdentifier:toObject:forCoder:]
31  0x1b730790  PostPhotoViewController Retain  7   00:19.254.993   0   UIKit   -[UIProxyObject initWithCoder:]
32  0x1b730790  PostPhotoViewController Retain  8   00:19.254.994   0   UIKit   -[UIRuntimeConnection initWithCoder:]
33  0x1b730790  PostPhotoViewController Retain  9   00:19.255.282   0   UIKit   -[UIRuntimeConnection initWithCoder:]
34  0x1b730790  PostPhotoViewController Retain  10  00:19.255.312   0   UIKit   -[UIRuntimeConnection initWithCoder:]
35  0x1b730790  PostPhotoViewController Retain  11  00:19.263.971   0   UIKit   -[UIProxyObject initWithCoder:]
36  0x1b730790  PostPhotoViewController Retain  12  00:19.263.971   0   UIKit   -[UIRuntimeConnection initWithCoder:]
37  0x1b730790  PostPhotoViewController Retain  13  00:19.264.922   0   UIKit   UINibDecoderDecodeObjectForValue
38  0x1b730790  PostPhotoViewController Retain  14  00:19.264.924   0   UIKit   UINibDecoderDecodeObjectForValue
39  0x1b730790  PostPhotoViewController Retain  15  00:19.264.939   0   UIKit   UINibDecoderDecodeObjectForValue
40  0x1b730790  PostPhotoViewController Retain  16  00:19.264.941   0   UIKit   UINibDecoderDecodeObjectForValue
41  0x1b730790  PostPhotoViewController Release 15  00:19.265.032   0   UIKit   -[UINib instantiateWithOwner:options:]
42  0x1b730790  PostPhotoViewController Release 14  00:19.265.046   0   UIKit   +[UIProxyObject removeMappingsForCoder:]
43  0x1b730790  PostPhotoViewController Release 13  00:19.265.049   0   UIKit   +[UIProxyObject removeMappingsForCoder:]
44  0x1b730790  PostPhotoViewController Release 12  00:19.265.060   0   UIKit   -[UINibDecoder finishDecoding]
45  0x1b730790  PostPhotoViewController Release 11  00:19.265.061   0   UIKit   -[UINibDecoder finishDecoding]
46  0x1b730790  PostPhotoViewController Release 10  00:19.265.076   0   UIKit   -[UINibDecoder finishDecoding]
47  0x1b730790  PostPhotoViewController Release 9   00:19.265.077   0   UIKit   -[UINibDecoder finishDecoding]
48  0x1b730790  PostPhotoViewController Release 8   00:19.265.095   0   UIKit   -[UINibDecoder finishDecoding]
49  0x1b730790  PostPhotoViewController Release 7   00:19.265.103   0   UIKit   -[UIRuntimeConnection dealloc]
50  0x1b730790  PostPhotoViewController Release 6   00:19.265.109   0   UIKit   -[UINibDecoder finishDecoding]
51  0x1b730790  PostPhotoViewController Release 5   00:19.265.118   0   UIKit   -[UIRuntimeConnection dealloc]
52  0x1b730790  PostPhotoViewController Release 4   00:19.265.126   0   UIKit   -[UIRuntimeConnection dealloc]
53  0x1b730790  PostPhotoViewController Release 3   00:19.265.133   0   UIKit   -[UIRuntimeConnection dealloc]
54  0x1b730790  PostPhotoViewController Release 2   00:19.265.548   0   Foundation  -[NSAutoreleasePool drain]
55  0x1b730790  PostPhotoViewController Retain  3   00:19.292.511   0   UIKit   -[UINavigationController topViewController]
56  0x1b730790  PostPhotoViewController Autorelease     00:19.292.517   0   UIKit   -[UINavigationController topViewController]
57  0x1b730790  PostPhotoViewController Retain  4   00:19.297.581   0   UIKit   -[UINavigationController topViewController]
58  0x1b730790  PostPhotoViewController Autorelease     00:19.297.585   0   UIKit   -[UINavigationController topViewController]
59  0x1b730790  PostPhotoViewController Retain  5   00:19.297.598   0   UIKit   -[UINavigationController _startTransition:fromViewController:toViewController:]
60  0x1b730790  PostPhotoViewController Release 4   00:19.297.619   0   UIKit   -[UINavigationController _startTransition:fromViewController:toViewController:]
61  0x1b730790  PostPhotoViewController Retain  5   00:19.297.957   0   UIKit   -[UINavigationController topViewController]
62  0x1b730790  PostPhotoViewController Autorelease     00:19.297.958   0   UIKit   -[UINavigationController topViewController]
63  0x1b730790  PostPhotoViewController Retain  6   00:19.298.000   0   UIKit   -[UIResponder becomeFirstResponder]
64  0x1b730790  PostPhotoViewController Release 5   00:19.298.015   0   UIKit   -[UIResponder becomeFirstResponder]
65  0x1b730790  PostPhotoViewController Release 4   00:19.302.098   0   QuartzCore  CA::AutoreleasePool::~AutoreleasePool()
66  0x1b730790  PostPhotoViewController Release 3   00:19.302.117   0   QuartzCore  CA::AutoreleasePool::~AutoreleasePool()
67  0x1b730790  PostPhotoViewController Release 2   00:19.302.696   0   QuartzCore  CA::AutoreleasePool::~AutoreleasePool()
68  0x1b730790  PostPhotoViewController Release 1   00:19.303.120   0   QuartzCore  CA::AutoreleasePool::~AutoreleasePool()
69  0x1b730790  PostPhotoViewController Retain  2   00:19.651.789   0   UIKit   -[UINavigationController topViewController]
70  0x1b730790  PostPhotoViewController Autorelease     00:19.651.789   0   UIKit   -[UINavigationController topViewController]
71  0x1b730790  PostPhotoViewController Retain  3   00:19.651.808   0   UIKit   -[UINavigationController topViewController]
72  0x1b730790  PostPhotoViewController Autorelease     00:19.651.809   0   UIKit   -[UINavigationController topViewController]
73  0x1b730790  PostPhotoViewController Retain  4   00:19.651.854   0   UIKit   -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
74  0x1b730790  PostPhotoViewController Release 3   00:19.651.862   0   UIKit   -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
75  0x1b730790  PostPhotoViewController Release 2   00:19.651.904   0   GraphicsServices    GSEventRunModal
76  0x1b730790  PostPhotoViewController Release 1   00:19.651.905   0   GraphicsServices    GSEventRunModal
77  0x1b730790  PostPhotoViewController Retain  2   00:20.841.683   0   UIKit   -[UINavigationController topViewController]
78  0x1b730790  PostPhotoViewController Autorelease     00:20.841.684   0   UIKit   -[UINavigationController topViewController]
79  0x1b730790  PostPhotoViewController Retain  3   00:20.841.704   0   UIKit   -[UINavigationController topViewController]
80  0x1b730790  PostPhotoViewController Autorelease     00:20.841.705   0   UIKit   -[UINavigationController topViewController]
81  0x1b730790  PostPhotoViewController Retain  4   00:20.841.706   0   UIKit   -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:]
82  0x1b730790  PostPhotoViewController Autorelease     00:20.841.707   0   UIKit   -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:]
83  0x1b730790  PostPhotoViewController Retain  5   00:20.841.716   0   UIKit   -[UINavigationController setDisappearingViewController:]
84  0x1b730790  PostPhotoViewController Release 4   00:20.841.720   0   UIKit   _popViewControllerNormal
85  0x1b730790  PostPhotoViewController Retain  5   00:20.841.732   0   UIKit   -[UIViewController removeChildViewController:notifyDidMove:]
86  0x1b730790  PostPhotoViewController Release 4   00:20.841.733   0   UIKit   -[UIViewController removeChildViewController:notifyDidMove:]
87  0x1b730790  PostPhotoViewController Release 3   00:20.843.840   0   UIKit   _UIApplicationHandleEvent
88  0x1b730790  PostPhotoViewController Release 2   00:20.843.841   0   UIKit   _UIApplicationHandleEvent
89  0x1b730790  PostPhotoViewController Release 1   00:20.843.842   0   UIKit   _UIApplicationHandleEvent
90  0x1b730790  PostPhotoViewController Retain  2   00:20.844.155   0   UIKit   -[UINavigationController _startTransition:fromViewController:toViewController:]
91  0x1b730790  PostPhotoViewController Release 1   00:20.844.178   0   UIKit   -[UINavigationController _startTransition:fromViewController:toViewController:]
92  0x1b730790  PostPhotoViewController Retain  2   00:20.845.394   0   UIKit   -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
93  0x1b730790  PostPhotoViewController Release 1   00:20.845.396   0   UIKit   -[UINavigationController setDisappearingViewController:]
94  0x1b730790  PostPhotoViewController Retain  2   00:20.845.410   0   UIKit   -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
95  0x1b730790  PostPhotoViewController Release 1   00:20.845.429   0   UIKit   -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
96  0x1b730790  PostPhotoViewController Release 0   00:20.845.437   0   UIKit   -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
97  0x1b730790  PostPhotoViewController Zombie  -1  00:23.145.572   0   UIKit   -[UITabBarController _tabBarItemClicked:]

【问题讨论】:

如果不了解更多关于如何设置视图控制器的信息,很难知道发生了什么。标签栏控制器不应该在导航控制器的导航堆栈中处理某些控制器。你能更全面地描述一下你的设置吗? 什么是UIPickerViewController?你的意思是UIImagePickerController?如果是这样,您是否在将其他控制器推入堆栈之前正确地解除了它?你在用故事板吗?如果是这样,可能会在问题中显示它......无论如何,您能否提供更多关于您的视图控制器如何适合/导航在一起的具体细节 想通了,由于某种原因,PostPhotoVC 被设置为 TabBarController 委托。删除固定的东西。 【参考方案1】:

PostPhotoViewController 出于某种原因被设置为 UITabBarController 委托。删除那些固定的东西。

【讨论】:

太棒了...我遇到了完全相同的问题!谢谢! 您好我有同样的问题,我必须在应用程序委托中删除标签栏委托

以上是关于视图控制器在发布后收到发送给它的消息,导致崩溃的主要内容,如果未能解决你的问题,请参考以下文章

响应者链的事件传递过程

DetailViewController 没有收到对象数组?

prepareForSegue 调用时不发送参数,导致崩溃

如何向视图控制器的视图发送消息?

核心数据多对多关系导致获取的结果控制器崩溃

iOS 内存泄漏导致更改视图控制器崩溃