ios - Set PFQueryTableViewCell imageView as a local image -


[developing ios using swift]

i pulling data parse , populating pfquerytableview it, , based on 1 of values of pfobjects using populate tableview, set imageview of cell image stored locally in xcode images.xcassets.

this code:

// set cells each row of table override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath, object: pfobject?) -> pftableviewcell? {      var cell = tableview.dequeuereusablecellwithidentifier("cell") as! pftableviewcell!     if cell == nil {         cell = pftableviewcell(style: uitableviewcellstyle.subtitle, reuseidentifier: "cell")     }      // set image read/unread      if let readstatus = object!["readstatus"] as? string {          if readstatus == "unread" {             cell.imageview?.image = uiimage(named: "unreadimage")         } else if readstatus == "read" {             cell.imageview?.image = uiimage(named: "readimage")         }      }      return cell  } 

but not set image...

if change line ! after imageview (like so): cell.imageview!.image = uiimage(named: "readimage")

i error:

fatal error: unexpectedly found nil while unwrapping optional value 

so how can set cell's image based on parse value (but want image local image)

something wrong cell object. first of all, don't need ! mark @ end. should have this:

let cell = tableview.dequeuereusablecellwithidentifier("cell") as! pftableviewcell 

in xcode 6.3 , swift 1.2 next line not compile because checking nil cannot nil - force unwrapping cell no more optional , don't need check nil.

so remove if cell == nil lines , see if cell set correctly in ib (check if you've set identifier).


Comments

Popular posts from this blog

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

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -