gpt4 book ai didi

ios - 在iOS模拟器中检测UIButton上的长按

转载 作者:行者123 更新时间:2023-12-01 19:04:17 30 4
gpt4 key购买 nike

我有一个 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)方法?您可能需要设置失败依赖项。具体来说,您可能需要返回 YESgestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: .

关于ios - 在iOS模拟器中检测UIButton上的长按,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20764615/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com