我已经按照教程进行了http://raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout 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;
}
有人可以建议一种更好的方法在自动布局中执行相同的操作并且我没有使用故事板吗?
我建议在单元格的内容视图上使用 Autolatyout 并在 viewDidLoad 中给出估计行高,如下所示self.tableView.estimatedRowHeight = 200;
不过这个apporach可能不支持早期版本的IOS。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)