[ViewControllergestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]:消息发送到释放实例 [英] [ViewController gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance
问题描述
我有一个简单的场景.
我将 myViewController
推送到导航堆栈上.
I push myViewController
onto navigation stack.
myViewController
基本上是在整个屏幕上显示集合视图.我在这个集合视图上添加了一个额外的 UIPanGestureRecognizer
并将 myViewController
设置为它的委托.我在 myViewController
中保留了对该平移手势识别器的强引用.
myViewController
is basically showing a collection view over entire screen. I added an additional UIPanGestureRecognizer
on this collection view and set myViewController
as its delegate. I am retaining a strong reference to that pan gesture recognizer inside myViewController
.
当我点击返回时,myViewController
从导航堆栈中弹出并释放.myViewController
的 dealloc
方法被调用.到目前为止,一切都按预期工作.
When I tap Back, myViewController
gets popped from the navigation stack and deallocated. The myViewController
's dealloc
method gets called as it should. Up to this point everything works as expected.
然后我尝试像第一次一样打开相同的 myViewController
并且崩溃发生消息:
Then I try to open the same myViewController
like the first time and the crash occurs with the message:
[MyViewController gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance
我在 myViewController
中实现了这个方法,它总是返回 YES
.但这甚至无关紧要,因为没有人甚至不应该调用此方法,因为没有人应该对它有强引用.显然有人仍然持有弱引用,因为 dealloc
方法是在唯一存在的实例上调用的.
I have this method implemented in myViewController
and it always returns YES
. But this shouldn't even matter because no one should even be calling this method because none should have a strong reference to it. Obviously someone is still holding a weak reference since the dealloc
method was called on the only instance that ever existed.
甚至没有调用 MyViewController
的 init
方法.
Not even the init
method of the MyViewController
gets called.
我尝试将以下代码同时放在 dealloc
和 viewWillDisappear
中:
I tried to put the following code both in dealloc
and in viewWillDisappear
:
[self.myPanGestureRecognizer removeTarget:self action:@selector(panGestureAction:)];
[self.collectionView removeGestureRecognizer:self.myPanGestureRecognizer];
self.myPanGestureRecognizer.delegate = nil;
self.myPanGestureRecognizer = nil;
但是,它没有改变任何东西.每次同样的事情 - myViewController 得到 initialized
并在第一次正常显示.第二次尝试初始化和推送时,出现异常.很明显,这和我添加的平移手势识别器有关,但我不知道如何.
But, it didn't change anything. Every time the same thing - myViewController gets initialized
and displayed normally the first time. The second time I try to initialize and push, the exception occurs. Obviously, it is related to the pan gesture recognizer that I added, but I don't see how.
推荐答案
这个问题的答案最终解决了我的非常相似的问题:gestureRecognizer shouldReceiveTouch 在释放的视图中持续导致崩溃
The answer to this question ended up fixing my issue that was very similar: gestureRecognizer shouldReceiveTouch persisting in deallocated view causing crash
我错误地将 self.navigationController.interactivePopGestureRecognizer.delegate 设置为 self.
I was incorrectly setting self.navigationController.interactivePopGestureRecognizer.delegate to self.
所以即使从 NSZombie 报告的错误是在另一个类中.它的手势识别器实际上并不是罪魁祸首,而是我的 InteractivePopGestureRecognizer.
So even though the error reported from the NSZombie was in another class. It's gesture recognizer was not actually the culprit, it was my interactivePopGestureRecognizer.
这篇关于[ViewControllergestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]:消息发送到释放实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!