2017-01-19 27 views
0

我有一個封閉獲取價值,並加入到numberOfRowsInSection迅速

getCitiesFromServer() { (success, result) in 

       countТ = Array(success.values).count 

} 

所以我想用它爲表生成細胞計數:

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

return countТ 
} 

如何從封閉得到countT並添加到numberOfRowsInSection

+0

你應該指定'陣列(成功.values)'到數據源數組,例如'cities'並在'numberOfRowsInSection'中返回'cities.count'。 – vadian

回答

1

你可以只重新加載的tableView一旦完成像這樣做:

getCitiesFromServer() { (success, result) in 

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

} 

這樣的計數將新的數據源服用。

但是一個更好的做法將是在numberOfRowsInSection返回類似

datasource.count 

其中

datasource = Array(success.values) 

,並已申報數據源爲類變量