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 as URL?'은'imageURL as! '이어야한다고 생각한다. URL' 함수가'URL'을 기다리고 있습니다.'URL' 옵션이 아닙니다. – 3stud1ant3
하드 코딩 된 더미 URL을 시도하면 변경 되나요? –
1. 항목을 인쇄하십시오. 가격 가치가 포함되어 있습니까? 2. 이미지의 경우 imageURL을 인쇄하고 브라우저에서이 URL을 열면 URL이 유효하지 않은지 알 수 있습니다. – Woof