iphone - 为什么 UITableView 的滑动删除有时工作正常有时不工作?

标签 iphone ios uitableview swipe

我的 View 上有一个UITableView,我想应用某个部分的滑动删除模式行。我实现的如下:

 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@">> canEditRowAtIndexPath");
    if (indexPath.section == CanDeletedSection) {
        return YES;
    }else{
        return NO;
    }
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@">> editingStyleForRowAtIndexPath");
    if (indexPath.section == CanDeletedSection) {
        return UITableViewCellEditingStyleDelete;
    }
    return UITableViewCellEditingStyleNone;
}
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSLog(@">> commitEditingStyle");
     if (editingStyle == UITableViewCellEditingStyleDelete) {
         // dosomething
     }
}

但是当我滑动表格行时,有时会出现 Delete 按钮,有时不会。 顺便说一下,我的单元格是自定义的并继承自 UITableViewCell

我已将 NSLog 添加到上述方法中。当 Delete 按钮没有出现时,我得到的日志是这样的:

>> editingStyleForRowAtIndexPath
>> canEditRowAtIndexPath

当出现Delete按钮时,日志如下:

>> editingStyleForRowAtIndexPath
>> canEditRowAtIndexPath
>> editingStyleForRowAtIndexPath
>> canEditRowAtIndexPath
>> canEditRowAtIndexPath
>> editingStyleForRowAtIndexPath

我制作了一个使用自定义单元格的演示,效果很好。所以问题是由包含 TableView 的 View Controller 引起的。 View Controller 继承自另一个 View Controller ,在那个 View Controller 中,有一个用于隐藏键盘的点击手势。但是当我从 View Controller 中删除它们时,结果是一样的。

最佳答案

请检查view或superview是否有其他手势。如果是这样,请确保在设置手势委托(delegate)后实现 UIGestureRecognizerDelegate 的以下方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
 return YES;
}

关于iphone - 为什么 UITableView 的滑动删除有时工作正常有时不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13929703/

相关文章:

iPhone - 尝试在 quartz 中创造发际线

iphone - 游戏套件点对点

html - 当 SMS 应用程序未在后台运行时,无法在 iPhone 上的 SMS 链接中预填充电话号码和消息正文

ios - 字典中的不同值(也称为元组)

iphone - _myObject 与 self.myObject

ios - WKWebView 可以调用主应用程序中的函数并获取值吗?

iphone - 为什么这会导致内存泄漏?

ios - 在 UISearchController Swift 中将标题与图像名称匹配

ios - 使特定的 UITableViewCells 具有不同的背景颜色

ios - uitableview重置删除按钮