本文介绍了UIButton& UITextField将阻止UITableViewCell被滑动删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

UITableViewCell 中有 UIButton UITextField 。当我在 UIButton上滑动时,删除按钮不会出现。 code>或 UITextField 。我确实在SO和Google上搜索答案,还有一个类似的问题,但没有正确的答案。

There are UIButton and UITextField in the UITableViewCell. The delete button will not come up when I swipe over UIButton or UITextField. I do search for the answers on SO and google, there is a similar questions Swipe left gestures over UITextField, but no correct answers.

我在iOS 8上遇到了此问题。

I got this problem on iOS 8.

编辑
设置 self.tableView.panGestureRecognizer.delaysTouchesBegan = YES; 后,它非常适合带有 UITextField 的单元格code>。但是,当我从 UIButton 开始拖动时,将显示删除按钮并触发 UIButton ,这是我不希望的。 UIButton 被解雇。

Edit After setting self.tableView.panGestureRecognizer.delaysTouchesBegan = YES;, it works perfect for cell with UITextField. But when i drag start from the UIButton, the delete button shows and the UIButton fired, which I do not want the UIButton get fired.

推荐答案

我不知道如何预防首先触发了 UIButton ,但 UITableViewCell 具有属性 showingDeleteConfirmation 可用于检查是否显示删除按钮。我要做的是在 TouchUpInside UIButton 操作中检查此内容,例如

I don't know how to prevent the UIButton from firing in the first place, but UITableViewCell has the property showingDeleteConfirmation that can be used to check whether the Delete button is being shown. What I do is check this in the UIButton action for TouchUpInside, like this

- (void)buttonPressed:(id)sender
{
    if (!self.showingDeleteConfirmation) {
        // Handle button press
    }
}

(此示例来自 UITableViewCell 子类,因此它使用 self 来访问属性。)

(This example is from a UITableViewCell subclass, so it uses self to access the property.)

除了

tableView.panGestureRecognizer.delaysTouchesBegan = YES;

可以正确识别滑动而未执行按钮操作。

that you already have, works to get the swipe properly recognized and the button action not performed.

这篇关于UIButton& UITextField将阻止UITableViewCell被滑动删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:27