2017-09-17 5 views
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! 

} 
+0

'imageURL as URL?'은'imageURL as! '이어야한다고 생각한다. URL' 함수가'URL'을 기다리고 있습니다.'URL' 옵션이 아닙니다. – 3stud1ant3

+1

하드 코딩 된 더미 URL을 시도하면 변경 되나요? –

+0

1. 항목을 인쇄하십시오. 가격 가치가 포함되어 있습니까? 2. 이미지의 경우 imageURL을 인쇄하고 브라우저에서이 URL을 열면 URL이 유효하지 않은지 알 수 있습니다. – Woof

답변

0

나는 이와 같이 작동하도록 모든 것을 갖추고 있습니다. 나는 모르겠다 : indexPath는 효과가 있지만 아무 것도 볼 수 없다.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    // let cell = tableView.dequeueReusableCell(withIdentifier: "BasicCell", for: indexPath) 
    let 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 

}