开发者

UITableView deletion not working

开发者 https://www.devze.com 2023-01-15 22:30 出处:网络
I am trying to delete a row from a UITableView. My UITableView is populated from a NSMutableArray named TableData.

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

精彩评论

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

关注公众号