我有一个 UIButton
在我的自定义 UITableViewCell
.我正在处理 UITableViewCell
中该按钮上的一些控制事件。通过以下代码。这取自 CellForRowAtIndexPath
方法。
cell.gestureButton.tag = indexPath.row ;
[cell.gestureButton addTarget:self action:@selector(cellTapped:) forControlEvents:UIControlEventTouchUpInside];
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(cellLongPressed:)];
lpgr.minimumPressDuration = 2.0; //seconds
lpgr.delegate = self ;
[cell.gestureButton addGestureRecognizer:lpgr];
我正在 iOS 7 模拟器上对此进行测试。我的问题是,对于第一个事件,
UIControlEventTouchUpInside
被执行,我可以看到结果并且我的 cellTapped 方法被正确调用。但在第二种情况下,我分配了
UILongPressGestureRecognizer
在我的按钮上,我在模拟器中看不到结果,cellLongPressed:
方法永远不会被调用。据我了解,我的代码没问题。所以,我想知道,问题出在哪里?我的代码有问题还是模拟器不支持这个功能?在此先感谢您的帮助。
最佳答案
我打赌lpgr
与另一个手势识别器冲突。您是否尝试过实现 UILongPressGestureRecognizer 的委托(delegate)方法?您可能需要设置失败依赖项。具体来说,您可能需要返回 YES
在 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
.
关于ios - 在iOS模拟器中检测UIButton上的长按,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20764615/