ios - Xcode 8.3 and Swift 3 :Display Image in Cell in UICollectionView from URL fetched and Stored in NSMutableArray -
i have fetched data web service using following piece of code
func ws_getrelatedrresourcepath(_ rresourceid:int, arrrresourceids:nsarray) { let refid = arrrresourceids.object(at: rresourceid); albummodel.getrelatedrresourcepath(parameters: refid anyobject?) { (responseobject,success) in if(success){ let tempresp = responseobject; if tempresp != nil { self.arrrelatedrresource.add(tempresp!) }else { if(responseobject != nil){ print(responseobject!); } } if rresourceid < arrrresourceids.count - 1 { self.ws_getrelatedrresourcepath(rresourceid + 1, arrrresourceids: arrrresourceids); }else{ print("done.") self.collectionsameseriesmedia.reloaddata(); self.setupmediaview(); apputils.stoploading(); } }
by implementing getting url of image stored in nsmutablearray named arrrelatedrresource.
i passing array cellforitemat follows
let cell = collectionsameseriesmedia.dequeuereusablecell(withreuseidentifier: "sameseriesmediaidentifier", for: indexpath) as! mediadetailscollectionviewcell var strimagepath = arrrelatedrresource[indexpath.row] as! string print(strimagepath); strimagepath = (strimagepath anyobject).replacingoccurrences(of: "\\" , with: ""); strimagepath = strimagepath.replacingoccurrences(of: "\"" , with: ""); print(strimagepath) cell.imgsameseriesmedia.sd_setimage(with: url(string: strimagepath)) return cell
edited :- (solved)
the problem array in storing data. array storing url "". solved silly issue adding following line of code in it.
strimagepath = strimagepath.replacingoccurrences(of: "\"" , with: "");
the issue solved this.
use sd_setimage completion handler , check if ur getting nil image.
var strimagepath = arrrelatedrresource[indexpath.row] as! string strimagepath = strimagepath.addingpercentencoding(withallowedcharacters: characterset.urlqueryallowed)! let url = url(string: strimagepath) if let url = url{ nslog("url = %@",url) cell.imgsameseriesmedia.sd_setimage(with: url url!, placeholderimage: nil, options: sdwebimageoptions(), completed: { (image: uiimage?, error: error?, cachetype: sdimagecachetype, imageurl: url?) in if image != nil{ cell.imgsameseriesmedia.backgroundcolor = uicolor.green } else{ cell.imgsameseriesmedia.backgroundcolor = uicolor.blue } }) }
wiki
Comments
Post a Comment