tableView visibleCells 上缺少单元格 swift

missing cell on tableView visibleCells swift

当我在 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)
    }

我没有您正在使用的 "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)
        })

    }