UITableView动态行高,不使用自动布局
我支持iOS 7,不使用自动布局。有没有一种方法可以让单元格标签以这种方式显示动态高度 谢谢 编辑: 这是我在iOS 7中用来定义动态高度的代码,看起来我可以用自动布局来实现它,但是它切断了底部的最后一个单元格,这很奇怪UITableView动态行高,不使用自动布局,uitableview,ios7,Uitableview,Ios7,我支持iOS 7,不使用自动布局。有没有一种方法可以让单元格标签以这种方式显示动态高度 谢谢 编辑: 这是我在iOS 7中用来定义动态高度的代码,看起来我可以用自动布局来实现它,但是它切断了底部的最后一个单元格,这很奇怪 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { var cell = offScreenCells.object
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
var cell = offScreenCells.objectForKey("gcc") as? GalleryCommentCell
if cell == nil {
cell = commentsTable.dequeueReusableCellWithIdentifier("GalleryCommentCustomCell") as? GalleryCommentCell
offScreenCells.setObject(cell!, forKey: "gcc")
}
let comment :GalleryCommentInfo = commentResults[indexPath.row]
setCellCommentInfo(cell!, data: comment)
cell!.bounds = CGRectMake(0, 0, CGRectGetWidth(commentsTable.bounds), CGRectGetHeight(cell!.bounds))
cell!.setNeedsLayout()
cell!.layoutIfNeeded()
let height = cell!.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height
return height + 1
}
func setCellCommentInfo(cell :GalleryCommentCell, data :GalleryCommentInfo) {
cell.commentDate.text = data.galleryCommentDate
cell.comment.text = data.galleryComment
}
在自定义单元格中,实现如下方法:
+ (CGFloat)heightForContactName:(NSString *)name
{
CGFloat height = 0.0f;
if (name) {
CGFloat heightForText;
// Calculate text height with `textBoundingRect`...
height += heightForText;
}
return height;
}
首先阅读UITableViewDelegate的文档。我尝试了多种解决方案,但都无效。最后一个细胞似乎被切断了,就在它的底部。我可以发布代码,我甚至尝试过使用autolayout。用您尝试过的内容更新您的问题,并解释您遇到的问题。将contentInset添加到表格底部似乎解决了截止问题,但不确定这是否是最有效的方法。