ios - TableView :didEndEditingRowAtIndexPath: delegate method called twice

标签 ios objective-c uitableview ios7 ios8.1

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

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;

willBegin... 被调用一次,而 didEnd... 被调用两次。这有什么原因吗?

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

有什么提示吗?

最佳答案

我的博客中描述了我的解决方案 Restore the selection of a UITableViewCell after cancelling the “Swipe to delete” operation (2014 年 12 月 22 日)。总而言之,使用一个 bool 值来跟踪操作。

我打开了一个雷达。我会等待回复,我会根据反馈进行更新。

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)
    }
}

关于ios - TableView :didEndEditingRowAtIndexPath: delegate method called twice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26974109/

相关文章:

objective-c - 将填充更改为已绘制的 NSBezierPath

objective-c - IOS:使用自定义表格 View 单元格重新加载表格 View

uitableview - iOS 8 单元格大小调整

ios - 如何将数据从一个 WKInterfaceController 推送到另一个?

iOS : 3. 4 : App names in iTunes Connect and as displayed on a device should be similar, 以免造成混淆

iphone - 指针和引用

iphone - 滚动之前加载 UITableView 中的所有单元格

ios - 如何围绕列绘制轮廓?

javascript - 在Cordova 4.0 iOS中无法将jpg/jpeg图像转换为Base64

iOS:图像在 UIImageView 中显示不正确