title: Static UITableViewCells with unknown rowHeight
body: <p>I've created a UITableView with static cells that will show hotel information loaded from Parse. These cells have the style Right Detail. The detailText is unknown to me so it can be quite long what means the cell will have an unknown height.</p>
  
  <p>I've tried to solve this using a NSMutableDictionary to store the allowed width of the detailLabel (this also dynamic because the left-side-labels change width because of being localised), calculate the height of the detailText and reload the data of the UITableView. This was not pretty.</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  {
      NSLog(@"displaying cell: %@", cell);
      NSLog(@"detailwidth : %f", cell.detailTextLabel.frame.size.width);
  
      if (indexPath.section != 0 &amp;&amp; ![[cellRefresh objectForKey:indexPath] boolValue]) {
          [self performSelector:@selector(customRefreshForCells:) withObject:cell afterDelay:0.5];
          [cellRefresh setObject:[NSNumber numberWithBool:YES] forKey:indexPath];
      }
  }
  
  - (void)customRefreshForCells:(UITableViewCell *)cell
  {
  
      NSLog(@"customRefreshForCells - detailwidth : %f", cell.detailTextLabel.frame.size.width);
  
      NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  
      NSArray *array = [NSArray arrayWithObjects:[NSNumber numberWithFloat:cell.detailTextLabel.frame.size.width], [NSNumber numberWithFloat:cell.detailTextLabel.frame.size.height], nil];
  
      NSLog(@"setting objects: %@, %@", array, indexPath);
  
      [cellDict setObject:array forKey:indexPath];
  
      [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  }
  
  - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      if (reloadedData == YES &amp;&amp; cellDict.count) {
          UILabel *label = [[UILabel alloc] init];
          label.font = [UIFont systemFontOfSize:16];
          label.numberOfLines = 0;
          label.lineBreakMode = NSLineBreakByWordWrapping;
          if (indexPath.section == 1) {
              if (indexPath.row == 0) label.text = _nameLabel.text;
              if (indexPath.row == 1) label.text = _cityLabel.text;
              if (indexPath.row == 2) label.text = _locationLabel.text;
              if (indexPath.row == 3) label.text = _addressLabel.text;
              if (indexPath.row == 4) label.text = _phoneLabel.text;
              if (indexPath.row == 5) label.text = _emailLabel.text;
              if (indexPath.row == 6) label.text = _siteLabel.text;
          } else if (indexPath.section == 2) {
              if (indexPath.row == 0) label.text = _breakfastLabel.text;
              if (indexPath.row == 1) label.text = _poolLabel.text;
              if (indexPath.row == 2) label.text = _callRoomLabel.text;
              if (indexPath.row == 3) label.text = _callReceptionLabel.text;
              if (indexPath.row == 4) label.text = _internetLabel.text;
              if (indexPath.row == 5) label.text = _remarksLabel.text;
          }
          label.frame = CGRectMake(0, 0, [[[cellDict objectForKey:indexPath] firstObject] floatValue], 0);
          [label sizeToFit];
          label.frame = CGRectMake(0, 0, [[[cellDict objectForKey:indexPath] firstObject] floatValue], label.frame.size.height);
  
  
          if (label.frame.size.height + 20 &gt; 44) { // 44 is the default
              return label.frame.size.height + 20;
          } else {
              return [super tableView:tableView heightForRowAtIndexPath:indexPath];
          }
      } else {
          return [super tableView:tableView heightForRowAtIndexPath:indexPath];
      }
  }
  </code></pre>
  
  <p>I've tried to create a custom nib for the cells but couldn't get this to work because of being static. Never got it loaded.</p>
  
  <p>It's stupid that I have to support iOS7. iOS8 has some cool new features to solve this :)</p>