我有一个简单的场景。
我将myViewController
推送到导航堆栈。
myViewController
基本上是在整个屏幕上显示集合视图。我在此集合视图中添加了额外的UIPanGestureRecognizer
,并将myViewController
设置为其委托。我在myViewController
内保留了对该手势识别器的强烈引用。
当我点按“返回”时,myViewController
会从导航堆栈中弹出并取消分配。 myViewController
dealloc
方法会被调用。到目前为止,一切都按预期工作。
然后我尝试像第一次一样打开相同的myViewController
,然后发生崩溃并显示消息:
[MyViewController gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance
我在myViewController
中实施了此方法,并始终返回YES
。但这并不重要,因为没有人应该调用这种方法,因为没有人应该对它有强烈的引用。显然有人仍然持有弱引用,因为dealloc
方法是在唯一存在的实例上调用的。
甚至不会调用init
的{{1}}方法。
我尝试将以下代码放在MyViewController
和dealloc
中:
viewWillDisappear
但是,它并没有改变任何东西。每次相同的事情 - myViewController得到[self.myPanGestureRecognizer removeTarget:self action:@selector(panGestureAction:)];
[self.collectionView removeGestureRecognizer:self.myPanGestureRecognizer];
self.myPanGestureRecognizer.delegate = nil;
self.myPanGestureRecognizer = nil;
并在第一次正常显示。我第二次尝试初始化和推送时,会发生异常。显然,它与我添加的平移手势识别器有关,但我不知道如何。
答案 0 :(得分:3)
这个问题的答案最终解决了我非常相似的问题: gestureRecognizer shouldReceiveTouch persisting in deallocated view causing crash
我错误地将self.navigationController.interactivePopGestureRecognizer.delegate设置为self。
所以尽管NSZombie报道的错误是在另一个班级。它的手势识别器实际上并不是罪魁祸首,它是我的interactivePopGestureRecognizer。