ios - CollectionView fatal error: unexpectedly found nil while unwrapping an Optional value -


i'm trying add collection view of images within array defined inside view did load method. app builds , runs fine when navigate specific section called "portfolio" app crashes giving me in console.

fatal error: unexpectedly found nil while unwrapping optional value

can figure out code below happening? i've tried wrapping issue in if statement , keeps crashing images won't display @ all. if define uibackgroundcolor works should.

import uikit  class portfolioview: uiviewcontroller, uicollectionviewdelegate, uicollectionviewdatasource {  var array:[string] = []  override func viewdidload() {      array = ["portimage1","portimage2","portimage3","portimage4","portimage5","portimage6","portimage7"]       super.viewdidload() }  override func didreceivememorywarning() {     super.didreceivememorywarning() }  func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {     return array.count }   func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {      var cell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) as! collectionviewcell      cell.imageview.image = uiimage(named: array[indexpath.row])       cell.imageview.layer.cornerradius = cell.imageview.frame.size.width / 2     cell.imageview.clipstobounds = true       cell.imageview.layer.borderwidth = 2.0     cell.imageview.layer.bordercolor = uicolor.whitecolor().cgcolor       return cell   } 

}

on face of it, , guessing because have not provided any of relevant information, appears you've defined class collectionviewcell has imageview property, have failed hook image view in storyboard / nib outlet imageview property. thus, @ load time, imageview property nil.


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? -