gpt4 book ai didi

ios - [ViewController gestureRecognizer :shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:02 27 4
gpt4 key购买 nike

我有一个简单的场景。

我将 myViewController 插入导航堆栈。

myViewController 基本上是在整个屏幕上显示一个 Collection View 。我在此 Collection View 上添加了一个额外的 UIPanGestureRecognizer 并将 myViewController 设置为其委托(delegate)。我在 myViewController 中保留了对平移手势识别器的强烈引用。

当我点击返回时,myViewController 从导航堆栈中弹出并释放。 myViewControllerdealloc 方法被正确调用。到目前为止,一切都按预期工作。

然后我尝试像第一次一样打开相同的 myViewController 并发生崩溃并显示消息:

[MyViewController gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance

我在 myViewController 中实现了这个方法,它总是返回 YES。但这应该无关紧要,因为没有人应该调用此方法,因为没有人应该对它有强引用。显然有人仍然持有弱引用,因为 dealloc 方法是在唯一存在的实例上调用的。

甚至 MyViewControllerinit 方法都不会被调用。

我尝试将以下代码同时放在 deallocviewWillDisappear 中:

[self.myPanGestureRecognizer removeTarget:self action:@selector(panGestureAction:)];
[self.collectionView removeGestureRecognizer:self.myPanGestureRecognizer];
self.myPanGestureRecognizer.delegate = nil;
self.myPanGestureRecognizer = nil;

但是,它并没有改变任何东西。每次都是同样的事情 - myViewController 得到 initialized 并在第一次正常显示。第二次尝试初始化和推送时,出现异常。显然,它与我添加的平移手势识别器有关,但我不知道如何。

最佳答案

这个问题的答案最终解决了我非常相似的问题: gestureRecognizer shouldReceiveTouch persisting in deallocated view causing crash

我错误地将 self.navigationController.interactivePopGestureRecognizer.delegate 设置为 self。

所以即使 NSZombie 报告的错误在另一个类中。它的手势识别器实际上并不是罪魁祸首,它是我的 interactivePopGestureRecognizer。

关于ios - [ViewController gestureRecognizer :shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28746123/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com