Ios 在Autolayout或使用NSAttributedString计算高度中,实现UITableViewCell动态高度的最佳方法是什么?

Ios 在Autolayout或使用NSAttributedString计算高度中,实现UITableViewCell动态高度的最佳方法是什么?,ios,objective-c,uitableview,autolayout,nsattributedstring,Ios,Objective C,Uitableview,Autolayout,Nsattributedstring,我遵循了从的教程,并实现了相同的,但随着iOS 8.3的发布,上面的教程似乎不起作用 因此,我切换回下面的代码,它工作得非常好 -(float)height :(NSMutableAttributedString*)string { NSAttributedString *attributedText = string; CGRect rect = [attributedText boundingRectWithSize:CGSizeMake(200, MAXFLOAT)

我遵循了从的教程,并实现了相同的,但随着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;
}

有人能建议一个更好的方法来做同样的自动布局,我不使用故事板

我建议在单元格的内容视图上使用Autolatyout,并在viewDidLoad中给出一个估计行高,如下
self.tableView.estimatedRowHeight=200但是,此应用程序可能不支持IOS的早期版本

在该教程中,什么不再起作用?内容标签的高度不会随着文本的增加而增加。我刚刚在viewDidLoad方法中添加了以下行“self.tableView.estimatedRowHeight=200”,并使其正常工作。我将进行反思,并将上述内容付诸实施,谢谢。