title: TableView app terminated due to 'NSInternalInconsistencyException'
body: <p>I'm trying to get the hang of UITableViews and everything that goes with it. At the moment I have the following code:</p>
  
  <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       return 10; 
  } 
  
  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       static NSString *CellIdentifier = @"Cell";
       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
  
       if (cell == nil) {
           cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
       }
  
       [cell.textLabel setText:[NSString stringWithFormat:@"I am cell %d", indexPath.row]];
  
       return cell; 
  }
  
  - (IBAction)killItem {
       NSIndexPath *indexToDelete = [NSIndexPath indexPathForRow:2 inSection:0];
       [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexToDelete] withRowAnimation:UITableViewRowAnimationRight];
  }
  </code></pre>
  
  <p>And I get the following error when initiating the "killItem" function:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (10) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'</p>
  </blockquote>
  
  <p>The way I understand it tableViews basically have a delegate and a data source where the data source, among other things, determines how many rows should be in the tableView. Through some searches here at stackoverflow I've found that this error is caused when the "data source doesn't match reality", when it's searching for rows that don't exist, that I have deleted.</p>
  
  <p>I might have gotten this wrong but that's what I think is doing it. So my question is, how do I get these to match so that I can avoid this error?</p>
  
  <p>For reference, I've looked in to the following posts without understanding what I need to do: </p>
  
  <p><a href="https://stackoverflow.com/questions/5000559/error-number-of-rows-in-section-in-uitableview-in-iphone-sdk">Error : Number of Rows In Section in UITableView in iPhone SDK</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5640820/slide-uitableviewcell">Slide UITableViewCell</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4148395/terminating-app-due-to-uncaught-exception-nsrangeexception-reason-nsmu">Terminating app due to uncaught exception &#39;NSRangeException&#39;, reason: &#39;*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]&#39;</a></p>
  
  <p>Adding <code>[tbl reloadData]</code>, <code>[tbl beginUpdate] ... [tbl endUpdate]</code> in the killItem function, doesen't seem to help my problem eighter.</p>
  
  <p>Thank you in advance, 
  Tobias Tovedal</p>