- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个简单的场景。
我将 myViewController
插入导航堆栈。
myViewController
基本上是在整个屏幕上显示一个 Collection View 。我在此 Collection View 上添加了一个额外的 UIPanGestureRecognizer
并将 myViewController
设置为其委托(delegate)。我在 myViewController
中保留了对平移手势识别器的强烈引用。
当我点击返回时,myViewController
从导航堆栈中弹出并释放。 myViewController
的 dealloc
方法被正确调用。到目前为止,一切都按预期工作。
然后我尝试像第一次一样打开相同的 myViewController
并发生崩溃并显示消息:
[MyViewController gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance
我在 myViewController
中实现了这个方法,它总是返回 YES
。但这应该无关紧要,因为没有人应该调用此方法,因为没有人应该对它有强引用。显然有人仍然持有弱引用,因为 dealloc
方法是在唯一存在的实例上调用的。
甚至 MyViewController
的 init
方法都不会被调用。
我尝试将以下代码同时放在 dealloc
和 viewWillDisappear
中:
[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/
这是我添加手势识别器的代码 UIImage *img = [UIImage imageWithContentsOfFile:media.thumbnailPath]; UIImageV
我正在尝试在我的应用程序上同时检测向上和向下滑动。我有一个 SKScene,我在 func didMoveToView: view 中添加了手势识别器我已设置委托(delegate):UIGestur
我有一个包含 UIPanGestureRecognizer 的 View 。同一个 View 还包含一个 UIScrollView。 当用户在 ScrollView 上平移时,我在 gestureRe
我有 viewdeck Controller ,我可以通过向右滑动来打开左侧栏菜单。对于我的中心 View Controller ,我也有 uitableview。 问题是我可以向右滑动来打开菜单,同
我有一个 UIScrollView,我向它添加了一个 UIPanGestureRecognizer。 我想同时使用 scrollView.panGestureRecognizer(默认)和我的自定义识
我有一个简单的场景。 我将 myViewController 插入导航堆栈。 myViewController 基本上是在整个屏幕上显示一个 Collection View 。我在此 Collecti
我有一个方法 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneou
我是一名优秀的程序员,十分优秀!