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

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,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(_:heightForRowAtIndexPath)而不是estimatedRowHeightAtIndexPath属性. estimatedRowHeightAtIndexPath主要用于smthg,如自缩细胞等.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...