我有抓住JSON和追加從JSON單個值到數組像這樣的方法:的UITableView不被填充
internal let methods = Methods()
var countryData = [""]
@IBOutlet weak var countryTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
displayCountries()
}
func displayCountries() {
// Wait for task to complete before grabbing JSON
methods.getCountriesData {() ->() in
for (_, value) in self.methods.getJSON() {
self.countryData.append(String(describing: value))
}
DispatchQueue.main.async {
self.countryTableView.reloadData()
print(self.countryData)
}
}
}
我的UITableView代表聲明,像這樣也:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return countryData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")! as UITableViewCell
let row = indexPath.row
cell.textLabel?.text = self.countryData[row]
return cell
}
print(self.countryData)打印日誌中的所有國家(100個國家),但由於某些原因,這些國家沒有顯示在UITableView中,有誰知道爲什麼?
有指定的表視圖的'dataSource'?表視圖的幀不是0x0? – nathan
我還沒有指定dataSource。 TableView的框架在視圖中可見,但沒有單元格 – KTOV
只有在指定表視圖的數據源時纔會調用這些'tableView'方法。這可以在代碼或故事板中完成。 – nathan