【问题标题】:missing cell on tableView visibleCells swifttableView visibleCells swift上缺少单元格
【发布时间】:2018-11-15 13:25:25
【问题描述】:

当我滚动到 tableView 中的第二行后在 tableView 中看到可见单元格时,它给我一个单元格丢失了 8 个单元格,它给我 7 个单元格这是我的代码

if response.count > 1
    {
        let index = IndexPath(row: 1, section: 0)
        self.tableView.scrollToRow(at: index, at: .top, animated: false)
    }
    if let _ = self.tableView {
        let cells = self.tableView.visibleCells
        UIView.animate(views: cells, animations: [], reversed: false, initialAlpha: 0, finalAlpha: 1, delay: 0, animationInterval: 0.1, duration: ViewAnimatorConfig.duration, options: UIView.AnimationOptions.allowAnimatedContent, completion: nil)
    }

【问题讨论】:

  • 很可能,因为您没有等待表格视图实际滚动到第 1 行,self.tableView.visibleCells 正在返回第 0 到第 7 行。
  • 我怎么能等待滚动?

标签: ios swift uitableview tableview swift4


【解决方案1】:

我没有您正在使用的“ViewAnimator”,所以我无法对其进行测试,但是这个应该适合您:

    if response.count > 1 {

        let index = IndexPath(row: 1, section: 0)
        self.tableView.scrollToRow(at: index, at: .top, animated: false)

        UIView.animate(withDuration: 0.1, animations: {
            self.tableView.layoutIfNeeded()
        }, completion: {
            _ in

            let cells = self.tableView.visibleCells

            // un-comment to output the array of visible cells
            // to debug console to confirm the desired rows are visible
            //print(cells)

            UIView.animate(views: cells, animations: [], reversed: false, initialAlpha: 0, finalAlpha: 1, delay: 0, animationInterval: 0.1, duration: ViewAnimatorConfig.duration, options: UIView.AnimationOptions.allowAnimatedContent, completion: nil)
        })

    }

【讨论】:

    猜你喜欢
    • 2014-12-16
    • 2015-04-20
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    相关资源
    最近更新 更多