title: ios 5: Invalid update: invalid number of rows in section
body: <p>I only have this problems with iOS 5, no problems with iOS 6</p>
  
  <p>This is my log</p>
  
  <pre><code>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 3.  The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
  </code></pre>
  
  <p>And my code</p>
  
  <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return [[dictionary allKeys] count];
  }
  
  
  -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
      NSArray *keyArray = [dictionary allKeys];
      return [[dictionary objectForKey:[keyArray objectAtIndex:section]] count];
  }
  
  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  {
  =    if (editingStyle == UITableViewCellEditingStyleDelete)
      {
  
          //First get all the keys of dictionary into one array
          NSArray *sectionsArray = [dictionary allKeys];
          //Get all the data of tapped section into one array by using indexpath.section
          NSMutableArray *objectsAtSection = [dictionary objectForKey:[sectionsArray objectAtIndex:indexPath.section]];
          //remove the particular object by using indexPath.row from the array
          [objectsAtSection removeObjectAtIndex:indexPath.row];
          // Update dictionary
  
          [table beginUpdates];
  
          // Either delete some rows within a section (leaving at least one) or the entire section.
          if ([objectsAtSection count] &gt; 0)
          {
              [dictionary setObject:objectsAtSection forKey:[sectionsArray objectAtIndex:indexPath.section]];
              // Section is not yet empty, so delete only the current row.
              // Delete row using the cool literal version of [NSArray arrayWithObject:indexPath]
              [table deleteRowsAtIndexPaths:@[indexPath]
                               withRowAnimation:UITableViewRowAnimationFade];
          }else{
              [dictionary removeObjectForKey:[sectionsArray objectAtIndex:indexPath.section]];
              // Section is now completely empty, so delete the entire section.
              [table deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
                       withRowAnimation:UITableViewRowAnimationFade];
          }
          [table endUpdates];
      }
  }
  </code></pre>
  
  <p>in iOS 5, after delete some row, and some section, i have this problems. </p>
  
  <p>Could you please help me?</p>