swift - 无法将“DataModel”类型的值分配给“String”类型?迅速
问题描述
类视图控制器: UIViewController,UITableViewDataSource,UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var madhu = [DataModel]()
override func viewDidLoad()
{
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
download{
self.tableView.reloadData()
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return madhu.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
let row = indexPath.row
cell.textLabel?.text = madhu[row]// here i got error "Cannot assign value of type 'DataModel' to type 'String?'"
return cell
}
}
我正在做 json 解码器程序我从 json 中检索数据并试图将其保留在表视图中。我遇到了这样的错误。请解决这个问题
解决方案
你需要
cell.textLabel?.text = madhu[row].title // e.x title
title
String 类型的模型中的属性名称在哪里
推荐阅读
- apple-push-notifications - 无法发送 iOS 推送通知 - 400 BadDeviceToken 响应
- javascript - 在 Jquery html 中的特定时间范围后启用按钮?
- angular - 特定输入的 Angular Material 日期选择器格式
- reactjs - react-native-svg:无法从 xml 创建 svg
- vb.net - 从互联网获取更新的 BTC 值
- swift - 关于 CLOSURE 的 SWIFT 语法问题
- flutter - 如何为外部类创建页面视图
- r - 更新 R 后 paste0 损坏
- python - 了解 Kafka 结束偏移量和已提交偏移量
- java - 从对象中删除重复项并合并到数组中