ios - After scrolling table cell image display previous images in swift. Though the image url display correct -


i have problem in cell image. describe in bellow.
screen having table containing 1000 cells.
each cell consist of a) image b) labels.
image , labels data comes json.
using of afnetwork purse json , bind label , image. problem in image. labels bind. json image url come correctly. display previous cell images when scrolling started. 1st time when scrolling not start image display perfectly. after scrolling problem start , show previous cell image.

code:

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     if self.arrpostimage![indexpath.row] as! string == ""     {         let cell1: cellnewnoimage = tableview.dequeuereusablecellwithidentifier("cell2") as! cellnewnoimage         return cell1      }      else      {          let cell1: cellformyactivitymaintableview = tableview.dequeuereusablecellwithidentifier("cell") as! cellformyactivitymaintableview         cell1.title.text = self.arrtitle![indexpath.row] as? string         cell1.postdate.text = self.arrpostdate![indexpath.row] as? string         cell1.postdescription.text = self.arrpostdescription![indexpath.row] as? string          //=========== problem  start  ====================                 self.arrpostpersonimg![indexpath.row] =  self.arrpostpersonimg![indexpath.row].stringbyaddingpercentencodingwithallowedcharacters(nscharacterset.urlqueryallowedcharacterset())!         let imgpath = self.arrpostpersonimg![indexpath.row]         let url12 = nsurl(string:imgpath as! string )         getdatafromurl(url12!) { (data, response, error)  in         dispatch_async(dispatch_get_main_queue()) { () -> void in             guard let data = data error == nil else { return }             cell1.postpersonimg.image = uiimage(data: data)         }     }     self.arrpostimage![indexpath.row] =  self.arrpostimage![indexpath.row].stringbyaddingpercentencodingwithallowedcharacters(nscharacterset.urlqueryallowedcharacterset())!     let imgpath2 = self.arrpostimage![indexpath.row]     let url122 = nsurl(string:imgpath2 as! string )     if let url = nsurl(string:imgpath2 as! string) {     if let data = nsdata(contentsofurl: url) {         cell1.postimage.image = uiimage(data: data)     }         } return cell1 } 

}

func getdatafromurl(url:nsurl, completion: ((data: nsdata?, response: nsurlresponse?, error: nserror? ) -> void)) {     nsurlsession.sharedsession().datataskwithurl(url)     { (data, response, error) in         completion(data: data, response: response, error: error)     }.resume() } 

when setting postpersonimage url set image view image nil before image path , try. like

cell1.postpersonimg.image = nil 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -