Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么UITableView';s滑动删除有时工作正常&;有时不是吗?_Iphone_Ios_Uitableview_Swipe - Fatal编程技术网

Iphone 为什么UITableView';s滑动删除有时工作正常&;有时不是吗?

Iphone 为什么UITableView';s滑动删除有时工作正常&;有时不是吗?,iphone,ios,uitableview,swipe,Iphone,Ios,Uitableview,Swipe,在我的视图上有一个UITableView,我想应用某个部分的滑动删除模式行。我实施的措施如下: - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@">> canEditRowAtIndexPath"); if (indexPath.section == CanDeletedSection) { retur

在我的视图上有一个
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
当出现
删除
按钮时,日志如下所示:

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

我已经做了一个演示,使用定制的细胞,它工作得很好。因此,问题是由包含表视图的视图控制器引起的。视图控制器继承自另一个视图控制器,在该视图控制器中,有一个用于隐藏键盘的点击手势。但是当我从视图控制器中删除它们时,结果是一样的

有时,特别是在模拟器中,很难正确执行滑动。您会发现,这很可能是物理问题,而不是编码问题


此外,您可能需要检查自定义单元格是否包含捕捉滑动的元素,并且没有将其传递到单元格。

请检查view或superview是否有任何其他手势。如果是这样,请确保在设置手势委托后执行以下
UIgestureRecognitizerDelegate
方法:

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

我也面临着同样的问题。。。 但最后我得到了解决方案:-

示例:-
self.navigationController.interactiveEPGESTurerecognizer.enabled=否

如果使用“CommitCommittedItingStyle”,则必须禁用该特定视图中的任何其他手势。


希望这能帮助你……:)

视图层次结构中其他位置的手势识别器可以拦截和阻止滑动动作

我在视图控制器中解决了这个问题:

@interface UIView (CellSwipeAdditions)
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
@end

@implementation UIView (CellSwipeAdditions)
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
        return YES;
    }
@end

感谢bademi带领我找到这个解决方案

CanDeletedSection的值是多少?它是一个节号。我只想在“CanDeletedSection”上实现滑动删除模式。我试着去掉这个限制,只对所有行应用这个模式,结果和以前一样。有时正常,有时不正常。您的代码应该可以正常工作。委托方法正在调用吗?请尝试放置NSLog以确保他们被呼叫。我确定他们被呼叫。我已经看到我必须先按下单元格,然后滑动删除按钮才能显示。这就好像桌子在视图中没有焦点,我必须先点击它一次才能使它有焦点。奇怪。但我的问题出在设备上。而且,这并不总是那么容易。确保你认真地从左到右刷卡,没有对角转向…——还要将
NSLog
语句放入代码中,以检查它是否正常工作。-另请参阅我在上面对自定义单元格的提示。自定义单元格中有一些
UILabels
UIImageView
,但没有捕获刷卡行为的函数。请尝试将图像视图的
userInteractionEnabled
设置为
YES
。默认情况下,它处于关闭状态。