我在我的collectionviewcell中添加了长按
lp = UILongPressGestureRecognizer(target: self, action: Selector("longPress:"))
lp.delegate = self
cell.tag = indexPath.row
cell.addGestureRecognizer(lp)
但如果我推送到其他viewController并使用swipe弹回,项目将崩溃!
所以我找网站来解决这个问题,我知道原因是我没有为代表获得UIGestureRecognizer
func gestureRecognizerShouldBegin(g: UIGestureRecognizer) -> Bool {
return true
}
我得到了这个例外
gestureRecognizerShouldBegin:]:无法识别的选择器发送到实例0x7fa9e0d8b7c0 2015-03-15 18:56:08.733 PicMemo [62182:5214628]由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [PicMemo.iViewController gestureRecognizerShouldBegin:]:无法识别的选择器发送到实例0x7fa9e0d8b7c0'
我想我在uilongpressgesturerecognizer crashes even if not implemented
中找到了解决方案但我不知道如何处理Swift。
答案 0 :(得分:0)
感谢@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;
}