ios - Swift 如何解决发送到实例 0x7fa9e0d8b7c0 的无法识别的选择器

标签 ios swift crash uigesturerecognizer

我在我的collectionviewcell中添加了长按

lp = UILongPressGestureRecognizer(target: self, action: Selector("longPress:"))
lp.delegate = self
cell.tag = indexPath.row
cell.addGestureRecognizer(lp)

但是如果我推送到其他 viewController 并通过滑动弹出,项目将会崩溃!

所以我寻找网站来解决这个问题,我知道原因是我没有获得委托(delegate)的 UIGestureRecognizer

func gestureRecognizerShouldBegin(g: UIGestureRecognizer) -> Bool {

    return true
}

我得到了这个异常

gestureRecognizerShouldBegin:]: unrecognized selector sent to instance 0x7fa9e0d8b7c0 2015-03-15 18:56:08.733 PicMemo[62182:5214628]Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PicMemo.iViewController gestureRecognizerShouldBegin:]: unrecognized selector sent to instance 0x7fa9e0d8b7c0'

我想我在 uilongpressgesturerecognizer crashes even if not implemented 中找到了解决方案

但我不知道如何使用 Swift。

最佳答案

感谢@HotLicks 有一个解决方案: 我们应该添加UIGestureRecognizerDelegate 然后添加

self.navigationController?.interactivePopGestureRecognizer.delegate = self

终于

func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer!) -> Bool {

    //self.navigationController?.popViewControllerAnimated(true) is also ok
    self.navigationController?.popToRootViewControllerAnimated(true)
    return true;
}

关于ios - Swift 如何解决发送到实例 0x7fa9e0d8b7c0 的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29060173/

相关文章:

swift - 如何要求信号量立即返回而不是等待信号?

ios - Collection View ( Collection View ,didSelectItemAt : indexPath) - Cannot call value of non-function type 'UICollectionView

ios - Swift IO 无法从字典转换为数组

ios - TableView 上的 EXC_BAD_ACCESS (SIGSEGV) :cellForRowAtIndexPath

ios - JSONModel 中的 NSMutableDictionary - EXC_BAD_ACCESS KERN_INVALID_ADDRESS

javascript - IOS HTML 禁用双击缩放

ios - 屏幕底部的 UIButton 仅间歇性突出显示

ios - Actionscript 3 是否有等效的 Reachability 类?

ios - 始终在 NSURLSessionDataTask 中取回缓存数据

java - 应用程序在启动时崩溃