tableView上缺少单元格visibleCells迅速

时间:2018-11-15 13:25:26

标签: ios swift uitableview tableview swift4

当我滚动到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 个答案:

答案 0 :(得分:0)

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

    }