ios - Pass data to UITableViewCell when initialising -


i have variable need pass main uitableview cell subview use in initialisation method. tried doing this:

class collectioncell : uitableviewcell {      var collectionelement  : pfobject = pfobject(classname:"collectionelement")      override init(style: uitableviewcellstyle, reuseidentifier: string?) {         super.init(style: style, reuseidentifier: reuseidentifier)      self.collectionelementarray = (collectionelement["elementfilearray"] as? [pfobject])!  ...  } 

i create cell in way:

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {  ...     let cell : collectioncell = tableview.dequeuereusablecellwithidentifier("collectioncell", forindexpath: indexpath) as! collectioncell      cell.collectionelement = collectionelements[indexpath.row]      return cell } 

the variable not set in init method.

as ncerezo says cells not getting created, getting recycled no init functions called. better approach use didset on collectionelement variable , whatever view updating based on new value there after ensuring isn't nil. when set property of cell in tableview(tableview: , cellforrowatindexpath:) cell update itself.

var collectionelement  : pfobject = pfobject(classname:"collectionelement") {     didset {         // update cell's view elements here, rather init function     } } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -