swift - UICollectionView not refreshing -


i downloading images , inserting them uicollectionview

these class members

var myitems:[uiimage] = [] var myview: uicollectionview? 

i have timer function receives img:uiimage object. insert uicollectionview this

        self.myitems.insert(img, atindex: self.myitems.count)         var count:int? = self.myview?.numberofitemsinsection(0)         var index:nsindexpath = nsindexpath(forrow: count!, insection: 0)         self.myview?.insertitemsatindexpaths([index]) 

i have function:

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

and one:

func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {     let cell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) mycollectionviewcell     cell.backgroundcolor = uicolor.orangecolor()     cell.textlabel.text = "text \(indexpath.row)"     cell.imageview.image = myitems[indexpath.row]     cell.backgroundview = uiimageview(image: uiimage(named: "cellbg"))     return cell } 

however view not show new images immediately. have tap on empty screen, new cell appears image. cannot scroll view if there more cells fit in view.

how refresh view? there wrong way dequeuing cell?

you forgot reload uicollectionview.

self.myview.reloaddata() 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -