ios - Pass parameter when initialising UICollectionViewCell -


i have uicollectionviewcell subclass , trying pass value cell when initialise it.

class additemcell: uicollectionviewcell {      var additembutton = uibutton()     var collectionelement  : pfobject?      override init(frame: cgrect) {         super.init(frame: frame)          additembutton = uibutton.buttonwithtype(uibuttontype.custom) as! uibutton         additembutton.frame = cgrectmake(0, 0, 170, 300)         additembutton.backgroundcolor = uicolor.redcolor()         additembutton.addtarget(self, action: "additemtocollectionelement:", forcontrolevents: uicontrolevents.touchupinside)         additembutton.settitle("new item", forstate: uicontrolstate.normal)         additembutton.titlelabel!.font =  uifont(name: "cochin-bolditalic", size: 20)         self.addsubview(additembutton)     }      init (frame: cgrect, passedcollectionelement : pfobject){         self.collectionelement = passedcollectionelement         super.init(frame: frame)     }      func additemtocollectionelement (sender : uibutton!) {      }      required init(coder adecoder: nscoder) {         super.init(coder: adecoder)     } } 

clearly method being called overridden one. there way call second / other way pass variable value?

if want initialize object parameters , make overridden init called you'll need use convenience initializer follow:

convenience init (frame: cgrect, passedcollectionelement : pfobject){     self.init(frame: frame)     self.collectionelement = passedcollectionelement } 

this way calling let cell = additemcell(frame:someframe, passedcollectionelement : someelement) initialize object calling both convenience , designated initializers. can learn more initialization here


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 -