Ios 如何在swift3中显示imagePath中的图像

Ios 如何在swift3中显示imagePath中的图像,ios,uitableview,swift3,uiimageview,Ios,Uitableview,Swift3,Uiimageview,我从soap得到的响应是图像路径 (self.posts.value(forKey:“image_path”)为![String])[indexPath.row] 这是我的回答 “” 我无法将此响应转换为我的url,我想在tableViewCell中显示此图像 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

我从soap得到的响应是图像路径

(self.posts.value(forKey:“image_path”)为![String])[indexPath.row]

这是我的回答

“”

我无法将此响应转换为我的url,我想在tableViewCell中显示此图像

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
        print((self.posts.value(forKey: "image_path") as! [String])[indexPath.row])

        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AlllLocationTableViewCell

         let urlString = (self.posts.value(forKey: "image_path") as! [String])[indexPath.row] as String
        print("\(urlString)")



        let fileUrl = NSURL(fileURLWithPath: (self.posts.value(forKey: "image_path") as! [String])[indexPath.row])
        print(fileUrl as Any)



            let data = try? Data(contentsOf: fileUrl) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch

                self.Responseimage = UIImage(data: data!)!



        cell.LocationImage?.image = LocationImagView1
    return cell as UITableViewCell


    }

首先,将
SDWebImage
库导入到项目中,然后根据需要在视图控制器中编写以下代码

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ItemCell", for: indexPath as IndexPath) as! ItemCell

    let urlStr = "https:\\images.com\image\12345.png".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)

    print("URL :: \(urlStr!)");

    cell.imgItem.sd_setImage(with: URL(string: urlStr!), placeholderImage: UIImage(named: "item_placeholder"), options: [.refreshCached, .retryFailed, .allowInvalidSSLCertificates])

    }else{
        cell.imgItem.image = UIImage (named: "item_placeholder")
    }

    return cell
}

您想显示URL中的图像还是ImagePath中的图像?@JagatDave来自ImagePath,因为我从soapImport SDWebImage库中获得了该路径…然后尝试我的答案。希望对您有所帮助。我已在您的重复问题中回答了如何加载图像: