Swift - UICollectionView repeats (duplicate) cells -


hi have array 100 pictures url's taken flickr. when use uicollectionview display 100 cells, 8 cells on screen , when scroll down see next 8 same previous , when execute

func collectionview(collectionview: uicollectionview!, cellforitematindexpath indexpath: nsindexpath!) -> uicollectionviewcell! 

and println("something") writes in console 8 time content of array 100

i use this:

func collectionview(collectionview: uicollectionview?, numberofitemsinsection section: int) -> int {     return self.photosurls.count } 

it makes 100 cells cells repeats always... knows how beat swift in new version of xcode gm seed ?

func collectionview(collectionview: uicollectionview!, cellforitematindexpath indexpath: nsindexpath!) -> uicollectionviewcell! {     let cell: imagecell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) imagecell     let imgurl = photosurls[indexpath!.row]     let api_url = nsurl.urlwithstring(imgurl)     let urlreq = nsurlrequest(url: api_url)     let nsopq:nsoperationqueue = nsoperationqueue()     nsurlconnection.sendasynchronousrequest(urlreq, queue: nsopq, completionhandler:{ (response: nsurlresponse!, data: nsdata!, error: nserror!) -> void in         if(error == nil){             cell.thewpimage!.image = uiimage(data: data)         }         })     return cell } 

i think not understand how uitableview , uicollectionview delegate methods work.

ios not load 100 cells @ same time because slow , not user experience. so, methods cellforitematindexpath or cellforrowatindexpath called when cells appear on screen.

whenever scroll down, see method cellforitematindexpathis called again make new cells. if put code println(indexpath.row) inside cellforitematindexpath, see cell number printed repeatedly when scroll or down.

if see same cells after scroll down, might due code on cellforitematindexpath. unable unless paste full source code above. or might bug in uicollectionview xcode gm seed.

how trying same project in xcode 6 beta 7 , report back? having problem uicollectionview in xcode gm well. related constraint. see: ios 8 gm not update constraints on collection views using xcode 6 beta 7 due that.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -