2017-06-05 28 views
0

我从SOAP响应作为IMAGE_PATH显示图像如何从ImagePath的在swift3

(self.posts.value(forKey: “IMAGE_PATH”)作为[字符串])[indexPath.row]

这是我的回应

http://sf.iipl.info/ImageCSharp.aspx?Location=C:\\infinityhost\\demo11.iipl.info\\data\\app\\user_location_photo\\8000034939_Resize\\&FileName=1_35f28e55-ca31-4918-8b41-9eb7f3070ace

我不能转换这个回答我的网址,我想在我的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 


    } 
+0

是否要显示来自URL或ImagePath的图像? –

+0

@JagatDave从imagePath因为我有肥皂的路径 – ViralRathod

+0

导入SDWebImage库...然后尝试我的答案。希望它对你有所帮助。 –

回答

0

首先进口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 
}