从UITableView删除一行后,它仍然显示

时间:2014-05-12 11:19:19

标签: ios objective-c uitableview

删除一行后,仍会显示。

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    Audio *current = [logic findAudioByRow:indexPath.row];
    [logic deleteAudio:current callback:^{
        dispatch_async(dispatch_get_main_queue(), ^{
           //some audio player logic that does not important for the topic
        });
    }];
}

此方法调用该函数:

-(void)deleteAudio:(Audio *)audio callback:(voidCallback)callback
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSString * ownerId = [NSString stringWithFormat:@"%ld", [audio.owner_id integerValue]];
        NSString * audioId = [NSString stringWithFormat:@"%ld", [audio.aid integerValue]];

        APIData *apiData = [[APIData alloc] initWithMethod:DELETE_AUDIO_BY_ID user:[[UserLogic instance] currentUser] queue:requestQueue params:[[NSMutableDictionary alloc] initWithObjectsAndKeys:audioId,@"aid", ownerId, @"oid", nil]];

        [APIRequest executeRequestWithData:apiData block:^(NSURLResponse *response, NSData *data, NSError *error) {
        }];
        callback();
        [self updateContent:YES];
    });
}

我不知道何时应该调用reloadData来更新视图。

2 个答案:

答案 0 :(得分:4)

无法在代码中看到删除方法。这就是你必须使用删除行方法的方法。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

        [mySourceArray removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

答案 1 :(得分:1)

删除一行表视图时,也要从数组中删除相关记录,然后重新加载tableview。