title: What is the best way to delete a section of a UITableView with static cells?
body: <p>Part of my iPhone app displays a <code>UITableView</code> with three, static sections in grouped format. However, in some instances (based on user input), it's most appropriate for the last of these sections not to appear when the view controller displays the table. </p>
  
  <p>In the <code>viewDidLoad</code> method of the controller, I've added the following lines of code that are executed conditionally:</p>
  
  <pre><code>if ([self.formula containsElementWithoutStableIsotopes]) {
      NSLog(@"Deleting section 2 ...");
      NSUInteger sectionToDelete = 2;
      [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionToDelete] 
                    withRowAnimation:UITableViewRowAnimationAutomatic];
  }
  </code></pre>
  
  <p>"Deleting section 2 ..." is logged to the console, so I know that this code is executing, but the table appears to be unaffected: all three sections are displayed as usual.  </p>
  
  <p>In the ideal case, I'd prefer section 2 to be deleted before the table view is even displayed, but I could live with it being deleted on appearing. However, if I place the code above within the <code>viewDidAppear</code> method instead, the program raises an <code>NSInternalInconsistencyException</code> because the number of sections before and after deletion do not match.</p>
  
  <p>I'd really appreciate your help on this topic. </p>