小编Eri*_*ega的帖子

如何在 swift 4 的集合视图中刷新数据?

我有一个函数每 2 秒刷新一次数组的数据

var timer = Timer()

func timeRefresh(){
    timer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(ViewController.refreshData), userInfo: nil, repeats: true)

}
Run Code Online (Sandbox Code Playgroud)

我从邮政服务接收数据

@objc func refreshData(){

    post(postString, Route) { (res) in

        let success = res["success"]

        if success == true {
            let walkers = res["walkers"]

            for secondItem in walkers.array! {
                let duration = secondItem["duration"]

                self.timeCar.append(duration.stringValue) //this is the info that i need for the collection view

                }
            }

            print("array time \(self.timeCar)")

        }else{
            self.timeCar = ["-.-","-.-","-.-","-.-","-.-"]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要每秒刷新集合视图

cell.typeLabel.text = …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview swift swift4

2
推荐指数
1
解决办法
8511
查看次数

标签 统计

ios ×1

swift ×1

swift4 ×1

uicollectionview ×1