ios - How can I reload data on my UICollectionView? -


i need reload images every time uicollectionview called. have 2 buttons (and more come) segue , populate uicollectionview via parse.com query. when click on button, images downloaded, , there segue uicollectionview, images display when tap "back" , re-enter uicollectionview. i've tried using self.collectionview.reloaddata() error.

var images = [uiimage]() var imagefiles = [pffile]() class collectioncollectionviewcontroller: uiviewcontroller, uicollectionviewdelegate, uicollectionviewdatasource {  @iboutlet weak var collectionview: uicollectionview!  @ibaction func xy1button(sender: anyobject) {    }  @ibaction func xy2button(sender: anyobject) {     var downloadimages = pfquery(classname: "xy2")     downloadimages.wherekey("expansion", equalto: "xy2")     downloadimages.findobjectsinbackgroundwithblock {         (objects: [anyobject]?, error: nserror?) -> void in         if error == nil {             println("successfully retrieved \(objects!.count) images.")             if let objects = objects as? [pfobject] {                 object in objects {                     imagefiles.append(object["image"] as! pffile)                 }             }         } else {             println("error: \(error!) \(error!.userinfo!)")         }     }      self.collectionview.reloaddata() //error above: "thread 1: exc_bad_instruction(code=exc_i386_invop, subcode=0x0)"      self.performseguewithidentifier("jumptocollectionview", sender: self) }  override func viewdidload() {    }  func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {      return imagefiles.count  }  func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {      let cell: cardscollectionviewcell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) as! cardscollectionviewcell     imagefiles[indexpath.row].getdatainbackgroundwithblock{         (imagedata: nsdata?, error: nserror?) -> void in          if error == nil {              let image = uiimage(data: imagedata!)              cell.img.image = image         }     }     return cell } } 

any help?!

try include self.collectionview.reloaddata() in asynchronous dispatches :

dispatch_async(dispatch_get_main_queue(), {         self.collectionview.reloaddata()     }) 

i hope have helped you!


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -