title: iOS - my heightForRowAtIndexPath implementation causes performance issues, why?
body: <p>I use a table view where I override <code>heightForRowAtIndexPath</code>. When I run the Xcode profiler I found the following: </p>
  
  <p><img src="https://i.stack.imgur.com/SYdvs.png" alt="enter image description here"></p>
  
  <p>I want to calculate the height based one object's property. I use the same table view for two kind of objects, <code>User</code> and <code>Post</code>. My implementation currently looks like this:</p>
  
  <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      NSString *text;
      Post *cellPost;
      User *cellUser;
      if (_pageType == FOLLOWERS || _pageType == FOLLOWING) {
          cellUser = [self.users objectAtIndex:indexPath.row];
          text = cellUser.userDescription.text;
          if (text == nil) {
              return 70;
          }
      } else {
          cellPost = [self.fetchedResultsController objectAtIndexPath:indexPath];
          text = cellPost.text;
      }
  
      CGSize boundingSize = CGSizeMake(245, CGFLOAT_MAX);
      CGSize requiredSize = [text sizeWithFont:[UIFont fontWithName:@"TisaMobiPro" size:15]
                                 constrainedToSize:boundingSize
                                     lineBreakMode:NSLineBreakByWordWrapping];
      CGFloat textHeight = requiredSize.height;
      CGFloat cellHeight = textHeight + 40;
      if ([cellPost.text isEqualToString:self.post.text]) {
          cellHeight += 44;
          if (cellHeight &lt; 114) {
              cellHeight = 114;
          }
      } else {
          if (cellHeight &lt; 70) {
              cellHeight = 70;
          }
      }
  
      if (cellPost.repostedBy != nil &amp;&amp; cellPost.youReposted.boolValue == NO &amp;&amp; _pageType != CONVERSATION) {
          cellHeight += 27;
      }
  
      return cellHeight;
  
  }
  </code></pre>
  
  <p>If I remove most of the code and only have, e.g. <code>return 100</code> the tableView's scrolling performance is much improved. Can you spot or give suggestions on something in my implantation that could cause this performance issue?</p>