ios - unexpectedly found nil while unwrapping an Optional value for UITableVewCell custom cell class -


when running code table view, trying instantiate custom cell , fill values , seems work find until gets putting values outlets.

couple notes :

  1. i know preferred method here use "tableview.dequeuereusablecellwithidentifier" in situation taking different route.

  2. also, outlets in custom cell hooked corresponding cell in story board.

  3. appropriate delegates setup.

thanks in advance.

class favoritespropertyviewcell: uitableviewcell {     @iboutlet weak var activityindicator: uiactivityindicatorview!     @iboutlet weak var cellpropertyimage: uiimageview!     @iboutlet weak var cellroomsvalue: uilabel!     @iboutlet weak var cellspacevalue: uilabel!     @iboutlet weak var cellpricerangevalue: uilabel!     @iboutlet weak var cellcitystatezipvalue: uilabel!     @iboutlet weak var celladdressvalue: uilabel!  } 

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell{  var newpropertycell: favoritespropertyviewcell = favoritespropertyviewcell()  newpropertycell.cellroomsvalue.text = "2 rooms" newpropertycell.cellspacevalue.text = "2000 sqft" newpropertycell.cellpricerangevalue.text = "20,000" newpropertycell.celladdressvalue.text = "123 address"  newpropertycell.cellcitystatezipvalue.text = "knoxvegas tn 37777"  return newpropertycell } 

the variables shown have values in them.

lastly, error : fatal error: unexpectedly found nil while unwrapping optional value

var newpropertycell: favoritespropertyviewcell = favoritespropertyviewcell()

none of outlets being set because no communication storyboard(xib) happening here, instantiate type. therefore of them nil.

the right approach use tableview.dequeuereusablecellwithidentifier, load ui storyboard (registered xib) you.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -