title: UITableView crash on updates after text edit
body: <p>So I'm totally stumped by this one and tempted to call "OS bug".</p>
  
  <p>I have a TableView controller with a single section, and in the header for that section there is an UITextField. Several operations result in rows being added/removed without a problem. However, as soon as text is edited in the header, and the keyboard dismissed, any insertion/removal of rows results in an immediate crash.</p>
  
  <p>And it can actually be simplified further - simply calling beginUpdates/endUpdates on the table once the keyboard is dismissed is enough to cause a crash. The end of the callstack is:</p>
  
  <pre><code>_CFTypeCollectionRetain
  _CFBasicHashAddValue
  CFDictionarySetValue
  -[UITableView(_UITableViewPrivate) _updateWithItems:withOldRowData:oldRowRange:newRowRange:context:]
  -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:]
  -[UITableView endUpdates]
  </code></pre>
  
  <p>I've put together a minimal example that demonstrates the problem.</p>
  
  <p>Complete Controller source: <a href="http://www.andrewgrant.org/public/TableViewFail.txt" rel="nofollow noreferrer">http://www.andrewgrant.org/public/TableViewFail.txt</a></p>
  
  <p>Example Project: <a href="http://www.andrewgrant.org/public/TableViewCrash.zip" rel="nofollow noreferrer">http://www.andrewgrant.org/public/TableViewCrash.zip</a></p>
  
  <p>Most relevant code:</p>
  
  <pre><code>- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  {
      // create header view
      UIView* header = [[[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 50.f)] autorelease];
  
      // text field
      UITextField* textField = [[[UITextField alloc] initWithFrame:CGRectMake(10.f, 12.f, 300.f, 28.f)] autorelease];
      textField.text = @"Edit, then 'Save' will crash";
      textField.borderStyle = UITextBorderStyleRoundedRect;
      textField.clearButtonMode = UITextFieldViewModeAlways;
      textField.delegate = self;
  
      [header addSubview:textField];
  
      return header;
  }
  
  - (BOOL)textFieldShouldReturn:(UITextField *)textField
  {
      // no purpose, but demonstrates updates work at this point
      [self.tableView beginUpdates];
      [self.tableView endUpdates];
  
      [textField resignFirstResponder];
  
      // immediate crash
      [self.tableView beginUpdates];
      [self.tableView endUpdates];
      return YES;
  }
  </code></pre>