4

我想知道用户何时对UITableView. 根据文档,UITableViewDelegate我应该使用的方法如下:

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

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

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

有什么提示吗?

4

2 回答 2

3

我的解决方案在我的博客中描述了取消“滑动删除”操作后对 UITableViewCell 的选择(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)
    }
}
于 2015-01-30T16:01:01.847 回答
2

我也遇到了这个问题,并且能够通过将 BOOL 声明为我的视图控制器的成员来解决它:

@interface ViewController ()

@property (nonatomic, assign) BOOL isEditingRow;

@end

@implementation ViewController

...

...然后在 UITableView 的委托方法中设置和读取 BOOL 的值:

-(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!
    }
}

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

于 2015-01-30T14:53:24.110 回答