【发布时间】:2020-09-14 14:22:57
【问题描述】:
我是 swift 和 iOS 的完整初学者,我正在尝试编写一些代码,这些代码将获取一些 json 并将其放入对象数组中,然后使用该数组来填充 tableview。
问题是当我尝试填充 tableview 时,它只打印第一个,所以它看起来像这样:
这里是代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "comicCell", for: indexPath) as! ComicCell
cell.title.text = comics?[indexPath.row].title
cell.dateOnSale.text = comics?[indexPath.row].dateOnSale
return cell
}
我试图在一个简单的 for 循环中打印对象数组,它工作正常,这让我相信我的问题出在上面的函数中
【问题讨论】:
-
您似乎混淆了
numberOfSections和numberOfRowsInSection。前者必须返回 1,后者必须返回comics.count。并且不要将数据源数组声明为可选。 -
@vadian 非常感谢!现在可以使用了
标签: ios swift uitableview swift3