0

所以我有一个带有按钮抽屉的滑动 UITableViewCell。对于另一个用户,我被引导到一个非常好的实现来获取 UITableViewCell 的 indexPath。不幸的是,当我尝试删除该行时出现错误。该对象确实删除成功。

-(void)checkButtonWasTapped:(id)sender event:(id)event {
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
    NSLog(@"%@", indexPath);
    if (indexPath != nil)
    {
        PFObject *object = [self.listArray objectAtIndex:indexPath.row];
        [object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            NSLog(@"%@", indexPath);
            [self.tableView beginUpdates];
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                                  withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView endUpdates];
            [self.tableView reloadData];
        }];
    }

}

谢谢你的帮助

4

1 回答 1

2

看起来您正在使用 Parse,这是一项非常好的服务,IMO。deleteInBackground:负责云删除,但您尚未从支持表的本地阵列中删除。尝试添加该行:

[self.listArray removeObject:object];

在你得到PFObject *object. 如果它不是一个可变数组,那么你需要一些额外的代码:

NSMutableArray *changeMyArray = [self.listArray mutableCopy];  // assume you're using ARC
[changeMyArray removeObject:object];
self.listArray = [NSArray arrayWithArray:changeMyArray];

此外,由于本地删除是快速同步发生的,因此您无需在云删除的完成块中进行表更新。把它放在内联...

    PFObject *object = [self.listArray objectAtIndex:indexPath.row];
    [self.listArray removeObject:object];

    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                              withRowAnimation:UITableViewRowAnimationFade];
    [self.tableView endUpdates];

    [object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        NSLog(@"%@", indexPath);
    }];
于 2013-03-26T00:37:46.740 回答