Autolayout 或使用 NSAttributedString 计算高度来实现 UITableViewCell 的动态高度,哪种方法最好?

Which is the best approach among Autolayout or calculating the height using NSAttributedString, to implement dynamic height of an UITableViewCell?

我已经按照 http://raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout 的教程进行操作并实现了相同的功能,但是随着 iOS 8.3 的发布,上述教程似乎不起作用。

因此我切换回以下代码,它工作得很好

-(float)height :(NSMutableAttributedString*)string
{
  NSAttributedString *attributedText = string;

  CGRect rect = [attributedText boundingRectWithSize:CGSizeMake(200, MAXFLOAT)
                                           options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                           context:nil];
  CGSize requiredSize = rect.size;
  return requiredSize.height;
}

并在

中调用相同的内容
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{   
  CGFloat heightOfcell = [self height:[array objectAtIndex:indexPath.row]];
  return heightOfcell;
}

有人可以建议一种更好的方法来在自动布局中做同样的事情,而我没有使用 StoryBoard 吗?

我建议在单元格的内容视图上使用 Autolatyout,并像这样在 viewDidLoad 中给出估计的行高 self.tableView.estimatedRowHeight = 200; 但是,此方法可能不支持 IOS 的早期版本。