0
我想要從mysql的項目列表,並顯示它們在應用程序中。 名稱出現,但圖像和價格沒有。圖像沒有顯示在表查看
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// let cell = tableView.dequeueReusableCell(withIdentifier: "BasicCell", for: indexPath)
var cell:UITableViewCell? =
tableView.dequeueReusableCell(withIdentifier: "BasicCell", for: indexPath)
if (cell == nil)
{
cell = UITableViewCell(style: UITableViewCellStyle.subtitle,
reuseIdentifier: "BasicCell")
}
// Get the location to be shown
let item: Location = locations[indexPath.row]
// let price=locations[indexPath.row].price
let price=(item.price as NSString).floatValue
let cellPrice = String(format: "%.2f",price)
let serverurl=NSURL(string: "https://myoscapp.com/boot/images/")
let imageaddress = locations[indexPath.row].image
let imageURL = NSURL.init(string: imageaddress, relativeTo: serverurl! as URL)
cell?.textLabel?.text=locations[indexPath.row].name
cell?.detailTextLabel?.text = cellPrice
cell?.imageView?.sd_setImage(with: imageURL! as URL)
cell?.setNeedsLayout() //invalidate current layout
cell?.layoutIfNeeded() //update immediately
return cell!
}
我認爲'imageURL作爲URL?'應該是'imageURL as! URL'作爲函數期望一個'URL'不是一個可選的'URL' – 3stud1ant3
它會被改變,如果你嘗試一個硬編碼的虛擬url? –
1.打印您的物品。它是否包含價格值? 2.爲圖像打印imageURL,並在瀏覽器中打開此URL,以便看到url是否無效。 – Woof