为什么 UITableView 的滑动删除有时可以正常工作&有时不是? [英] Why does UITableView's swipe delete sometimes work fine & sometimes not?

查看:29
本文介绍了为什么 UITableView 的滑动删除有时可以正常工作&有时不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图中有一个 UITableView,我想应用某个部分的滑动删除模式行.我实现的内容如下:

There is a UITableView on my view, I want to apply swipe-delete-mode rows of a certain section. What I have implemented is as follows:

 - (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.

But when I swipe the table row, sometimes the Delete button appears, sometimes not. Incidentally, my cell is customized and inherits from UITableViewCell.

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

I have added the NSLog to above methods. When the Delete button not appears the log I got like this:

>> editingStyleForRowAtIndexPath
>> canEditRowAtIndexPath

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

When the Delete button appears, the log as below:

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

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

I have made a demo that using the customized cell, it works fine. So the problems are caused by the view controller which contains the table view. The view controller inherits from another view controller, in that view controller, there is a tap gesture which used to hide the keyboard. But when I removed them from the view controller, the result is same.

推荐答案

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

Please check whether view or superview has any other gestures. If so, make sure that you implement below method of UIGestureRecognizerDelegate after setting gesture delegate:

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

这篇关于为什么 UITableView 的滑动删除有时可以正常工作&有时不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆