自定义了一个UITableViewCell用于展示一些新闻信息,类似于图里的样子,Cell里的内容不是固定的,有时候有图片有时候没有图片,标题和说明文字的长度也不确定。自定义的这个Cell是纯代码的,而且没有用到AutoLayout布局,请问这样的话如何才能自动调整Cell的高度呢?
试过用 UITableViewAutomaticDimension
但是并不管用。网上的文章大部分都是需要配合AutoLayout一起使用才行,但对于有时候可能没图片这个问题不知道用AutoLayout应该怎样实现。
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
对应indexPath创建一个数组,然后计算啊,很简单的