这是自动布局或计算使用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 /动态表视图细胞高度自动布局并实施相同,但与iOS 8.3的发布,上面的教程似乎并不奏效。
I have followed the tutorial from http://raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout and implemented the same, but with the release of iOS 8.3, the above tutorial doesn't seem to be working.
所以我切换回以下code这工作绝对没问题。
Therefore i switched back to the following code which works absolutely fine
-(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;
}
可有人建议这样做的自动布局同样一个更好的办法,我没有使用故事板?
Can someone suggest a better way for doing the same in auto-layout and i am not using StoryBoard?
推荐答案
我会建议对细胞的内容视图使用Autolatyout并给予viewDidLoad中估计的行高这样的 self.tableView.estimatedRowHeight = 200;
然而,这apporach可能不支持IOS的早期版本。
I would suggest use Autolatyout on cell's content view and give an Estimated Row Height in viewDidLoad like this self.tableView.estimatedRowHeight = 200;
However this apporach may not support the Earlier versions of IOS.
这篇关于这是自动布局或计算使用NSAttributedString,实现一个的UITableViewCell的动力高度的高度之间的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!