title: XCODE TableView with multiple sections and delegate datasource from array of arrays - can't delete row without error?
body: <p>I have a TableView with multiple sections that's got a delegate  Data Source which links to an array of arrays. Each array within the array of arrays is it's own Table View Section. I have it loading up correctly and have an edit button enabled but when I try and delete my app crashes with the following error.</p>
  
  <p>*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (9) must be equal to the number of sections contained in the table view before the update (10), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'</p>
  
  <p>Now I am NOT deleting a section so am somewhat confused, here is a sample of my code. I have searched this forum extensively but just can't find out what I have done wrong.</p>
  
  <p>HERE IS MY CODE:</p>
  
  <pre><code>// Calculate how many sections in the table view from the array or arrays
  
  - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
  
      AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
  
      NSInteger sections = [delegate.packing.packingListArray count];
  
      return sections;
  }
  
  // Load the array and extract the count of items for each section
  
  - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  
      // For each array within the array of array count the items
      AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
      NSArray *sectionContents = [delegate.packing.packingListArray objectAtIndex:section];
      NSInteger rows = [sectionContents count];
  
      return rows;
  }
  
  // Load the list into the table view
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
      // Set the cell identifier - using ID field thats been set in interface builder
      static NSString *CellIdentifier = @"DestinationCell";
  
      // Re-use existing cell?
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      // If no reusabled cells then create a new one
      if (cell == nil){
          cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
      }
  
      // Add the relevant packing list array from the array of arrays
      AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
      NSArray *sectionContents = [delegate.packing.packingListArray objectAtIndex:[indexPath section]];
      NSString *contentForThisRow = [sectionContents objectAtIndex:[indexPath row]];
  
      cell.textLabel.text = contentForThisRow;
  
  
  
      // Return the formatted cell with the text it needs to display in the row
      return cell;
  }
  
  // Delete row from table and update data source array
  
  - (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *) indexPath {
  
      if (editingStyle ==UITableViewCellEditingStyleDelete) {
  
  
          [tableView beginUpdates];
  
          // Delete the item from the array
          AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
          [delegate.packing.packingListArray  removeObjectAtIndex:indexPath.row];
  
  
          // Delete the row from the table view
          [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  
          [tableView endUpdates];
  
      }
  
  
  }
  </code></pre>
  
  <p>I have a feeling this is something to do with perhaps the complication of the array of arrays creating multiple sections but there mus be someway of doing this?</p>
  
  <p>Any help much appreciated as I've been looking at this same code now for hours.</p>