ios - tableViewvisibleCells swift 上缺少单元格

标签 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)
    }

最佳答案

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

    }

关于ios - tableViewvisibleCells swift 上缺少单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53320509/

相关文章:

ios - navigationcontroller 回到上层navigationcontroller

iOS 10 Beta 使导航栏按钮和标题在 pushViewController 上消失

javascript - React 的 webkit.messageHandlers 将 JavaScript 注入(inject) Swift

ios - 第一个 TableView 部分之前的边距

ios - iOS 7 中的本地化 : Selects the language settings used previously

ios - 找不到符号 : _NSUserActivityTypeBrowsingWeb

ios - Swift 4+实例化符合协议(protocol)的类变量

php - 通过php上传图片到服务器

arrays - 用于填充 SWIFT 中 Tableview 部分的结构体和数组

Xcode 6.1.1 将 TableView 更改为静态单元格时崩溃