首页 > 解决方案 > 无法将“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 中检索数据并试图将其保留在表视图中。我遇到了这样的错误。请解决这个问题

标签: swiftxcode

解决方案


你需要

cell.textLabel?.text = madhu[row].title  // e.x title 

titleString 类型的模型中的属性名称在哪里


推荐阅读