title: UITableView: Handle cell selection in a mixed cell table view static and dynamic cells
body: <p>I am trying to mix dynamic and static cells in a grouped table view: I would like to get <strong>two sections with static cells</strong> at the top followed by a <strong>section of dynamic cells</strong> (please refer to the screenshot below). I have set the table view contents to <strong>static cells</strong>.</p>
  
  <p><img src="https://i.stack.imgur.com/fansU.png" alt="Mixing dynamic and static table view cells"></p>
  
  <h1>Edit</h1>
  
  <p>Based on AppleFreak's advice I have changed my code as follows:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"Cell";
      UITableViewCell *cell;
      if (indexPath.section &lt;= 1) { // section &lt;= 1 indicates static cells
          cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; 
      } else { // section &gt; 1 indicates dynamic cells
          CellIdentifier = [NSString stringWithFormat:@"section%idynamic",indexPath.section];
          cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
      }
  return cell;
  
  }
  </code></pre>
  
  <p>However, my app crashes with error message </p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception
    'NSInternalInconsistencyException', reason: 'UITableView dataSource
    must return a cell from tableView:cellForRowAtIndexPath:'</p>
  </blockquote>
  
  <p>for section 0 and row 0. The cell returned from <code>cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]</code> for section 0 and row 0 is <code>nil</code>.</p>
  
  <p>What is wrong with my code? Could there be any problems with my outlets? I haven't set any outlets because I am subclassing <code>UITableViewController</code> and supposedly do not any outlets for tableview to be set (?). Any suggestions on how to better do it?</p>
  
  <p><img src="https://i.stack.imgur.com/fansU.png" alt="enter image description here"></p>
  
  <h1>Edit II</h1>
  
  <p>I have recreated my scene in storyboard (please refer to my updated screen shot above) and rewritten the view controller in order to start from a new base. I have also read the description in Apple's forum as applefreak suggested. However, I run in my first problem with the method <code>numberOfSectionsInTableView:tableView</code>, in which I increment the number of static sections (two) by one.</p>
  
  <pre><code>  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return [super numberOfSectionsInTableView:tableView] + 1 ; }
  </code></pre>
  
  <p>The app crashed with the error message: </p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSRangeException', reason:
    '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]'</p>
  </blockquote>
  
  <p>Why is this code not working for me even though I followed Apple's and applefreak recommendations? It is possible that the tableView has changed a bit in iOS 6?</p>
  
  <p><strong>Solution</strong>: I got this to work now using AppleFreaks code sample in his answer below. Thank you, AppleFreak!</p>
  
  <h2>Edit III: Cell Selection:</h2>
  
  <p>How can I handle <strong>cell selection</strong> in a mixed (dynamic and static cells) cell table view? 
  When do I call <code>super</code> and when do I call <code>self tableView</code>? 
  When I use </p>
  
  <pre><code>[[super tableView] selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]
  </code></pre>
  
  <p>and try to check for the selected index paths with: </p>
  
  <pre><code>UITableView *tableView = [super tableView];
  if ( [[tableView indexPathForSelectedRow] isEqual:customGrowthIndexPath] ) { .. }
  </code></pre>
  
  <p>I get an return value of <code>nil</code>. </p>
  
  <p>As I can't find the source of my error, I really would appreciate your help</p>