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

本当に素晴らしいサービスであるIMOであるParseを使用しているようです。はクラウドの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 に答える