UITableView自我调整单元格滚动问题,细胞高度差异很大

Muk*_*esh 8 uitableview ios swift ios8 uitableviewautomaticdimension

  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()
}
Run Code Online (Sandbox Code Playgroud)

每个单元格的高度差异为200-400,因此尝试实现高度计算.estimatedHeightForRowAtIndexPath我不能将此方法中的精确估计高度作为计算的bcz

并在willDisplayCell方法中缓存高度,但滚动跳转仍然需要时间来渲染.

单元格就像Facebook卡片类型布局,有很多动态数据,文本和图像可变.可以有人帮助我.谢谢

小智 0

如果您能够计算每个单元格的高度,只需使用 tableView(_:heightForRowAtIndexPath) 而不是estimatedRowHeightAtIndexPath 属性。estimatedRowHeightAtIndexPath 主要用于自动调整单元格大小等。