我想知道用户何时对 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/