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 :
i know preferred method here use "tableview.dequeuereusablecellwithidentifier" in situation taking different route.
also, outlets in custom cell hooked corresponding cell in story board.
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 }   
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
Post a Comment