PDA

View Full Version : UITableView error when deleting row in iphn 2.2 fixed




mr tickle
May 25, 2009, 02:21 PM
Im not sure if this has been mentioned before, but it took me a while to find this, and i didnt locate it on any forums

when running my application (table view with the option to delete) in iphone 2.2 sim, it would crash out saying that the number of rows should equal the number of rows previously (plus or minus 1).

i was feeding data from a mutablearray, so it was confusing as hell, and even when i traced out values, it seemed all fine, then, i thought

what happens if the operation is happening before i delete from the array...

so i reversed the following

[tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath.......
[self.myArray removeObjectAtIndex:indexPath.row];

TO >>>

[self.myArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath.......

and it works

thus meaning, that the whole reload must have been happening before i had a chance to remove from the array, and checked the total length against its rows, which was not the case in iphone 2.1.

hope this helps someone. And hope it makes sense



mraheel
May 25, 2009, 08:06 PM
Thanks for sharing, these things are kinda tough to figure out given how xcode changes

dejo
May 26, 2009, 11:07 AM
Thanks for sharing, these things are kinda tough to figure out given how xcode changes
How Xcode changes? What do you mean? :confused: