Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从闭包中获取值并添加到numberOfRowsInSection swift_Swift_Closures - Fatal编程技术网

从闭包中获取值并添加到numberOfRowsInSection swift

从闭包中获取值并添加到numberOfRowsInSection swift,swift,closures,Swift,Closures,我有个了结 getCitiesFromServer() { (success, result) in countТ = Array(success.values).count } 所以我想用它来生成表中的单元格计数: func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return countТ } 如何从闭包中获取countT

我有个了结

getCitiesFromServer() { (success, result) in

                countТ = Array(success.values).count

}
所以我想用它来生成表中的单元格计数:

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return countТ
}

如何从闭包中获取countT并将其添加到numberOfRowsInSection?

完成后,您可以像这样重新加载tableView:

getCitiesFromServer() { (success, result) in

            countТ = Array(success.values).count
            tableview.reloadData()

}
这样,将从新数据源中获取计数

但更好的做法是在numberOfRowsInSection中返回类似的内容

datasource.count 
在哪里

datasource = Array(success.values)
并且已将datasource声明为类变量

您应该将ArraySucces.Value分配给数据源数组,例如cities和return cities.count in numberOfRowsInSection。