Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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
Ios tableView:didEndEditingRowAtIndexPath:委托方法调用了两次_Ios_Objective C_Uitableview_Ios7_Ios8.1 - Fatal编程技术网

Ios tableView:didEndEditingRowAtIndexPath:委托方法调用了两次

Ios tableView:didEndEditingRowAtIndexPath:委托方法调用了两次,ios,objective-c,uitableview,ios7,ios8.1,Ios,Objective C,Uitableview,Ios7,Ios8.1,我想知道用户何时在UITableView的单元格上应用滑动操作。根据文档,我应该使用的UITableViewDelegate方法如下: - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath; - (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPat

我想知道用户何时在
UITableView
的单元格上应用滑动操作。根据文档,我应该使用的
UITableViewDelegate
方法如下:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;
调用一次
willBegin…
,而调用两次
didEnd…
。这有什么原因吗

我的目标是了解用户何时在单元格上执行了滑动手势,然后是取消手势(他不想删除任何内容)。这是为了在未执行任何操作时恢复上一个选定的单元格(根据)


有什么提示吗?

我也遇到了这个问题,通过向我的视图控制器声明一个BOOL作为成员来解决这个问题:

@interface ViewController ()

@property (nonatomic, assign) BOOL isEditingRow;

@end

@implementation ViewController

...
。。。然后在UITableView的委托方法中设置并读取布尔值:

-(void)tableView: (UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath*)indexPath
{
    self.isEditingRow = YES;
}

-(void)tableView: (UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath*)indexPath
{
    if (self.isEditingRow)
    {
        self.isEditingRow = NO;

        // now do processing that you want to do once - not twice!
    }
}

这更像是一种解决办法,但发生这种情况时非常令人沮丧。

我的博客(2014年12月22日)中描述了我的解决方案。总之,请使用跟踪操作的布尔值

我打开了雷达。我将等待答复,并将更新反馈

func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {

    self.swipeGestureStarted = true
}

func tableView(tableView: UITableView, didEndEditingRowAtIndexPath indexPath: NSIndexPath) {
    if(self.swipeGestureStarted) {
        self.swipeGestureStarted = false

        self.tableView.selectRowAtIndexPath(self.selectedIndexPath, animated: true, scrollPosition: .None)
    }
}

我看不到这种行为。创建一个功能最少的简单表视图。你还看到这种行为吗?可能您当前的代码正在执行导致双重调用的操作。@rmaddy我使用UITableView设置了一个最小的示例代码,并且该行为仍然存在。这在模拟器上发生。我要试试这个设备。谢谢。@rmaddy问题仅限于模拟器。我目前正在使用8.1。够奇怪的了,我收回了。在iOS 8.1下(至少),我看到两个调用
didEndEditing
。这是在真正的设备上。我有一个一行的表视图。我刷了一下就删除了<调用了code>willBeginEditing。删除按钮出现。然后我点击了行外的表视图,调用了两次
didEndEditing
。我想知道这是否是iOS 8的问题。@rmaddy我运行的是iOS 7设备,其中源代码是用iOS 8.1和xCode 6.1编译的。我只看到一个电话。我没有尝试使用iOS 8设备。我应该上传一个雷达。这是我不久前写的关于这个主题的帖子。我还创造了一个雷达@我很高兴我们得出了相同的结论:)