无法使用类型为“(Int?)”的参数列表调用类型“String”的初始值设定项

Sri*_*tty -1 ios swift

在我的应用程序中,我从数组中的模型文件中获取数据,并将该数组发送到下一个 vc。

当我使用尝试使用代码时,我面临以下问题:

无法使用类型为“(Int?)”的参数列表调用类型“String”的初始值设定项

extension Invoiceview:UITableViewDelegate,UITableViewDataSource
{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        invoicetableviewhight.constant = CGFloat(30*Orderdata.count)
        return Orderdata.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "InvoiceTableViewCell")as! InvoiceTableViewCell
        let model = Orderdata[indexPath.row]
        cell.ordertype.text = model.prodName
        cell.orderprice.text = String(model.price)






        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 30
    }
}
Run Code Online (Sandbox Code Playgroud)

任何建议如何解决此错误?

小智 9

更新

cell.orderprice.text = String(model.price)
Run Code Online (Sandbox Code Playgroud)

if let priceOfProduct = model.price {
   cell.orderprice.text = String(priceOfProduct )
}
else{
   cell.orderprice.text = "";
}
Run Code Online (Sandbox Code Playgroud)