编辑 UI 表视图,在滑动和按钮显示之间调用



在显示删除按钮之前向左滑动UITableViewCell时,我可以在哪里调用方法?

- (void)tableView:(UITableView *)tableView commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //DELETE IS TAPPED

    }
}

滑动手势应该可以工作。

- (void)viewDidLoad
{
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                              action:@selector(swipeLeft:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    [self.tableView addGestureRecognizer:recognizer];
}
- (void)swipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer
{
    CGPoint location = [gestureRecognizer locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
    // Do whatever you need to do to the cell.
}

啊,找到了一种方法。 如果其他人很好奇,这似乎在显示删除按钮之前就可以解决问题 -

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"BAZINGA");
    return UITableViewCellEditingStyleDelete;
}

最新更新