【问题标题】:UIButton & UITextField will block UITableViewCell being swipe to deleteUIButton & UITextField 将阻止 UITableViewCell 被滑动删除
【发布时间】:2014-10-18 05:33:21
【问题描述】:

UITableViewCell 中有UIButtonUITextField。当我扫过UIButtonUITextField 时,删除按钮 不会出现。我确实在 SO 和 google 上搜索过答案,有类似的问题 Swipe left gestures over UITextField,但没有正确答案。

我在 iOS 8 上遇到了这个问题。

编辑 设置self.tableView.panGestureRecognizer.delaysTouchesBegan = YES; 后,它适用于UITextField 的单元格。但是当我从UIButton 开始拖动时,会显示删除按钮并触发UIButton,我不希望UIButton 被触发。

【问题讨论】:

  • 我猜你必须在删除一行后重新加载 tableview
  • @NullData 我已经更新了我的问题。请确保您了解我的问题。
  • @NullData 在代码中没有什么特别之处,单元格是在情节提要中创建的,并且可以通过在 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 中返回 YES 来编辑单元格.
  • 你的意思是最右边的删除按钮不会出现?我无法重现它。
  • 确保在按钮上滑动。

标签: ios uitableview delete-row


【解决方案1】:

我不知道如何防止UIButton 首先触发,但UITableViewCell 具有属性showingDeleteConfirmation,可用于检查是否显示删除按钮。我所做的是在TouchUpInsideUIButton 操作中检查这一点,就像这样

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

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

这个,除了

tableView.panGestureRecognizer.delaysTouchesBegan = YES;

您已经拥有,可以正确识别滑动并且未执行按钮操作。

【讨论】:

    猜你喜欢
    • 2014-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多