我在我的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/