UITableView Editing problem - Data deletes, but rows don't! I can't figure it out!

Discussion in 'iOS Programming' started by ethana, Aug 11, 2008.

  1. ethana macrumors 6502a

    Joined:
    Jul 17, 2008
    Location:
    Seattle, WA
    #1
    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
     
  2. ethana thread starter macrumors 6502a

    Joined:
    Jul 17, 2008
    Location:
    Seattle, WA
    #2
    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.
     

Share This Page