【问题标题】:Dynamic height UITableViewCell flickering动态高度 UITableViewCell 闪烁
【发布时间】:2021-08-04 14:07:45
【问题描述】:

我有一个动态高度 UITableViewCell 在滚动回顶部时闪烁的问题。

我已将.estimatedRowHeight.rowHeight 的值设置为UITableView.automaticDimension

我的限制如下图所示:

字幕标签可以有 1 到 20 行。有了这些约束,我确实得到了我想要的——布局本身看起来很棒。当我滚动到 TableView 的末尾时——一切正常,但是当我开始向上滚动时——UI 闪烁。

可能是什么问题以及如何解决?

【问题讨论】:

    标签: swift uitableview autolayout


    【解决方案1】:

    您可以尝试以下解决方案,希望对您有所帮助:-

     var cellHeights: [IndexPath : CGFloat] = [:]
    
    
    
     func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cellHeights[indexPath] = cell.frame.size.height
     }
    
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
     }
    
     func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return cellHeights[indexPath] ?? 100.0
     }
    

    【讨论】:

    • 感谢您的帮助!不幸的是,这并不能解决滚动回顶部时的闪烁问题。
    猜你喜欢
    • 2014-03-27
    • 2016-07-27
    • 1970-01-01
    • 2019-10-12
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    相关资源
    最近更新 更多