我有抓住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