title: Parse iOS SDK: Dynamic cell height for PFQueryTableViewController based on results from Query
body: <p><strong>Scenario</strong> </p>
  
  <p>I have an app that downloads data from my parse.com database and displays it into a PFQueryTableViewController. The PFQTVC has multiple (6) prototype cells each with their own reuseIdentifier as well as most importantly, their own height. I am currently using the following design to find the correct height for each <code>indexPath.row</code>...</p>
  
  <p><strong>Currently</strong></p>
  
  <p><em>this works before enabling paging</em></p>
  
  <p>Each cell is unique as each one displays different types of information. So I am checking for each <code>self.objects</code> by each unique quality they have.</p>
  
  <pre><code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  
                          // \!/ -trouble maker 
      PFObject *object = [self.objects objectAtIndex:indexPath.row];
      NSString *orientation = object[@"orientation"];
  
      NSNumber *height;
  
      if ([orientation  isEqual: @"left"] || [orientation  isEqual: @"right"]) {
  
          height = @400.0;
      }
  
      else if ([orientation  isEqual: @"up"] || [orientation  isEqual: @"down"]) {
  
          height = @500.0;
      }
  
      else if (blah blah blah) {
  
          //ect.
      }
  
      return [height floatValue];
  } 
  </code></pre>
  
  <p>This all works. That is, before I enable paging. </p>
  
  <p><strong>When I enable paging</strong></p>
  
  <p>Like most apps mine needs to be able to page through data, and that's what mine does. I set my <code>objectsPerPage</code> to 10 - <em>problem is, when I scroll down to that tenth cell and reload the next page...</em></p>
  
  <pre><code>...reason: '*** -[__NSArrayM objectAtIndex:]: index 11 beyond bounds [0 .. 10]'
  </code></pre>
  
  <p><strong>Reason</strong></p>
  
  <p>When it loads the next page, <code>self.objects</code> in heightForRowAtIndexPath is an NSArray that does not get loaded with the new objects. This is causing my app to crash and making me very frustrated.</p>
  
  <p><strong>Question</strong></p>
  
  <p>Does anybody know how to fix this issue? </p>
  
  <p><strong>EDIT</strong> </p>
  
  <pre><code>NSNumber *height;
  
  if (indexPath.row &gt; self.objects.count) {
  
      height = @50.0;
  }
  
  else {
  
      PFObject *object = [self.objects objectAtIndex:indexPath.row];
  
      NSString *orientation = object[@"orientation"];
  
      if ([orientation  isEqual: @"left"] || [orientation  isEqual: @"right"]) {
          //HAS COMMENTS
          if ([[object objectForKey:@"comments"]intValue] &gt; 0) {
  
  
              height = @618.0;
  
          }
  
          else {
  
  
              //NO COMMENTS BUT HAS LIKES
              if ([[object objectForKey:@"likes"]count] &gt; 0) {
  
  
                  height = @398.0;
  
              }
              //HAS NOTHING
              else {
  
  
                  height = @381.0;
  
              }
  
          }
  
      }
  
      else if ([orientation  isEqual: @"up"] || [orientation  isEqual: @"down"]) {
  
          if ([[object objectForKey:@"comments"]intValue] &gt; 0) {
  
  
              height = @727.0;
  
          }
  
          else {
  
  
              if ([[object objectForKey:@"likes"]count] &gt; 0) {
  
  
                  height = @508.0;
  
              }
  
              else {
  
                  height = @490.0;
  
              }
  
          }
  
      }
  
      return [height floatValue];
  
  }
  </code></pre>