【发布时间】:2016-05-20 09:50:50
【问题描述】:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let json = JSON(data: activityTableView.onlineFeedsData)[indexPath.row] // new
if(json["topic"]["reply_count"].int > 0){
if let cell: FeedQuestionAnswerTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier_reply) as? FeedQuestionAnswerTableViewCell{
cell.selectionStyle = .None
cell.tag = indexPath.row
cell.relatedTableView = self.activityTableView
cell.configureFeedWithReplyCell(cell, indexPath: indexPath, rect: view.frame,key: "activityTableView")
// Make sure the constraints have been added to this cell, since it may have just been created from scratch
cell.layer.shouldRasterize = true
cell.layer.rasterizationScale = UIScreen.mainScreen().scale
return cell
}
}else{
if let cell: FeedQuestionTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? FeedQuestionTableViewCell{
cell.selectionStyle = .None
cell.tag = indexPath.row
cell.relatedTableView = self.activityTableView
cell.configureFeedCell(cell, indexPath: indexPath, rect: view.frame)
// Make sure the constraints have been added to this cell, since it may have just been created from scratch
cell.layer.shouldRasterize = true
cell.layer.rasterizationScale = UIScreen.mainScreen().scale
return cell
}
}
return UITableViewCell()
}
每个单元格的高度有200-400的差异,所以尝试在estimatedHeightForRowAtIndexPath中实现高度计算。我不能用这种方法精确估计高度作为计算的bcz
并在willDisplayCell 方法中缓存高度,但滚动仍然会跳跃,就像渲染需要时间一样。
该单元格类似于 Facebook 卡片式布局,其中包含大量动态数据以及可变高度的文本和图像。有人可以帮助我吗?谢谢
【问题讨论】:
-
你能告诉我更多关于如何计算
tableView(_:estimatedHeightForRowAtIndexPath:)中单元格的高度吗?
标签: ios swift uitableview ios8 uitableviewautomaticdimension