ios - Custom UICollectionViewCell not showing UIImage and crashes -


i'm using custom uicollectionviewcell call examplecell, within uicollectionview, , images trying set cells not showing up, , app crashes. found similar question here, , followed comments best of knowledge, didn't help.

when comment out

self.collectionview!.registerclass(redeemcell.self, forcellwithreuseidentifier: reuseidentifier) 

inside examplecollectionviewcontroller, app doesn't crash shows black boxes (since set cell background color black) instead of actual images. if uncomment out line, app crashes error

fatal error: unexpectedly found nil while unwrapping optional value 

examplecollectionviewcontroller.swift :

import uikit  private let reuseidentifier = "examplecell" private let sectioninsets = uiedgeinsets(top: 50.0, left: 20.0, bottom: 50.0, right: 20.0)  class examplecollectionviewcontroller: uicollectionviewcontroller {     let examples = example.allexamples()      override func viewdidload() {         super.viewdidload()          // register cell classes         self.collectionview!.registerclass(examplecollectionviewcell.self, forcellwithreuseidentifier: reuseidentifier)     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }      // mark: uicollectionviewdatasource      override func numberofsectionsincollectionview(collectionview: uicollectionview) -> int {         return 1     }      override func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {         return examples.count     }      override func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> examplecell {         let cell = collectionview.dequeuereusablecellwithreuseidentifier(reuseidentifier, forindexpath: indexpath) as! examplecell         cell.backgroundcolor = uicolor.blackcolor()         cell.configureforexample(examples[indexpath.row])         return cell     } } 

examplecell.swift :

import uikit  class examplecell: uicollectionviewcell {     @iboutlet weak var exampleimageview: uiimageview!      func configureforexample(example: example) {         exampleimageview.image = example.image     } } 

example.swift

import uikit  @objc class example {     let image: uiimage?      init(image: uiimage?) {         self.image = image     }      class func allexamples() -> array<example> {         return [example(image: uiimage(named: "neutral")),             example(image: uiimage(named: "sad")),             example(image: uiimage(named: "happy")) ]     } } 

in identity inspector, have custom classes set examplecollectionviewcontroller , examplecell. also, in attributes inspector, have "examplecell" set identifier under "collection reusable view" examplecell.

any ideas may doing incorrectly?

apparently if set background color , try set image,

        cell.backgroundcolor = uicolor.blackcolor()         cell.configureforexample(examples[indexpath.row]) 

the black color shows on image. when got rid of line black background color, images showed up. , think spent hours on this, lol.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -