title: Dynamically sized tableview in UIViewController
body: <p>This might take a little explaining.  I have a UIViewController subclass that contains a label and a tableview directly underneath (the label and some other controls being the reason I can't use a UITableViewController subclass).  Because the tableview contents are dynamic, I can't set it's height directly when I add it.  So, I am doing the following in loadView:</p>
  
  <pre><code>//add the table view with no size for now
      tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
      tableView.dataSource = self;
      tableView.delegate = self;
      tableView.scrollEnabled = NO;
  
  //now that the datasource is set, use the delegates to update the height
      [tableView layoutIfNeeded];
      [tableView setFrame:CGRectMake(0, self.y_position, 320, [tableView contentSize].height)];
  
  //add it to my scrollview, which contains all controls in this view
      [scrollView addSubview:tableView];
  </code></pre>
  
  <p>This works well so far (though alternative ideas would be nice to hear).</p>
  
  <p>The problem comes when I enter edit mode for my view.  I want to modify the contents of the table view, inserting an additional section and row.  So far, I have the following implementation of setEditing:</p>
  
  <pre><code>- (void)setEditing:(BOOL)editing animated:(BOOL)animated{   
      [tableView beginUpdates];
      [super setEditing:editing animated:animated];
  
      //insert or remove the section and row 
      NSRange range = NSMakeRange(0, 1);
      if (self.isEditing) {
          [tableView insertSections:[NSIndexSet indexSetWithIndexesInRange:range] withRowAnimation:UITableViewRowAnimationAutomatic];
      }
      else {
          [tableView deleteSections:[NSIndexSet indexSetWithIndexesInRange:range] withRowAnimation:UITableViewRowAnimationAutomatic];
      }
  
      [nameAndIngredientsTableView endUpdates];
  </code></pre>
  
  <p>}</p>
  
  <p>The additional section and row are added just fine, but the bottom rows of the table view are cut off since it's size hasn't been updated.  How should I do this?</p>
  
  <p>I attempted to use the same code again - layoutIfNeeded and then setting the height manually, but this doesn't seem to do anything</p>
  
  <p>I'd love to know what I should be looking at to dynamically resize the tableview when coming in and out of edit.</p>