【发布时间】:2021-12-28 09:54:06
【问题描述】:
我在 UIKit 中使用领域。我设置了保存到领域,一切都显示在 MongoDB Realm Studio 中,但是当我希望这些数据显示在 UITableView 中时,什么都没有。 我写了一个扩展,好像没有错误,但是不明白为什么数据不显示。
extension ViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return spendingDBArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomTableViewCell
let spending = spendingDBArray[indexPath.row]
cell.recordCategory.text = spending.category
cell.recordMoney.text = "\(spending.cost)"
print("work")
switch spending.category {
case "Home": cell.recordImage.image = #imageLiteral(resourceName: "Frame 4")
case "Clothes": cell.recordImage.image = #imageLiteral(resourceName: "Frame 8")
case "Connection": cell.recordImage.image = #imageLiteral(resourceName: "Frame 7")
case "Auto": cell.recordImage.image = #imageLiteral(resourceName: "Frame 3")
case "Pharmacy": cell.recordImage.image = #imageLiteral(resourceName: "Frame 2")
case "Products": cell.recordImage.image = #imageLiteral(resourceName: "Frame 1")
case "Cafe": cell.recordImage.image = #imageLiteral(resourceName: "Frame 6")
case "Other": cell.recordImage.image = #imageLiteral(resourceName: "Frame 5")
default:
cell.recordImage.image = #imageLiteral(resourceName: "Rectangle 1")
}
return cell
}
}
【问题讨论】: