开发者

UITableView deletion not working

I am trying to delete a row from a UITableView. My UITableView is populated from a NSMutableArray named TableData. When I am deleting a row and reloading the tableview, it shows that the last row has been removed [not the selected row]. But when I NSLog() the contents of the mutable array it shows that the selected row has been removed.

This is my code:

- (void)tableView:(UITableView *)tableView commitEditingStyl开发者_开发百科e:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [TableData removeObjectAtIndex:indexPath.row];
        [tableView reloadData]; 

        for (int i = 0; i < [TableData count]; i++) 
        {
            NSLog(@"Value at %d :%@", i, [TableData objectAtIndex:indexPath.row]);
        }   
    }   
}


Don't call reloadData instead, call [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜