Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ethana

macrumors 6502a
Original poster
Jul 17, 2008
836
0
Seattle, WA
Ok, I have a a UITableView and it's being populated with data from a SQLite database. Just as an example, my TableView has three rows and looks like this when it's loaded initially:

Hats
Coats
Shirts

Then when I click the Edit button, the minus sign comes up and they look like this:

- Hats
- Coats
- Shirts

When I click the - sign next to Coats, the following code runs:
Code:
- (void)tableView:(UITableView *)tableView 
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath {
		
if (editingStyle == UITableViewCellEditingStyleDelete) {
		
// SQL "Delete" code goes here and it works. The item is deleted from my DB		
	
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
withRowAnimation:UITableViewRowAnimationFade];
		
}	
}

Now here's the problem... my Coats item gets deleted, and Shirts bumps up into its place. But Shirts also appears right under it as well. It looks like this:

- Hats
- Shirts
- Shirts

What the hell? Why does a second Shirts appear? Also, when I close my program and reopen it, its displayed correctly now, with just Hats and Shirts (2 items).

How do I make my TableView reload or refresh with the correct data? Why isn't the third row getting deleted?

Ethan
 
Found out that I wasn't removing my object from the array, so my 'tableView:numberOfRowsInSection:' count wasn't working correctly, thus causing the problem.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.