views:

26

answers:

1

Hi Friends, 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 reloaded the tableview, it shows that the last row has been removed [not the selected row]. But when i NSLog the contents of mutable array it shows that the selected row has been removed.

This is my code

- (void)tableView:(UITableView *)tableView commitEditingStyle:(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]);
}   

}
}

[SORRY FOR MY POOR ENGLISH]

+2  A: 

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

jrtc27
Your code worked correctly. Thank you
new_programmer
No problem - glad I could help ;)
jrtc27