ios - Custom UITableViewCell not showing on table view -
i trying create custom uitableviewcell
. here code:
class importedcontactstvcell: uitableviewcell { var namelabel = uilabel(frame: cgrect(x: 0, y: 0, width: 100, height: 20)) var emaillabel = uilabel(frame: cgrect(x: 0, y: 0, width: 100, height: 20)) var phonelabel = uilabel(frame: cgrect(x: 0, y: 0, width: 100, height: 20)) override func awakefromnib() { super.awakefromnib() // initialization code namelabel.settranslatesautoresizingmaskintoconstraints(false) emaillabel.settranslatesautoresizingmaskintoconstraints(false) phonelabel.settranslatesautoresizingmaskintoconstraints(false) contentview.addsubview(namelabel) contentview.addsubview(emaillabel) contentview.addsubview(phonelabel) var viewsdict = [ "namelabel" : namelabel, "emaillabel" : emaillabel, "phonelabel" : phonelabel ] contentview.addconstraints(nslayoutconstraint.constraintswithvisualformat("v:|-[namelabel]-[emaillabel]-[phonelabel]-|", options: nslayoutformatoptions( 0 ), metrics: nil, views: viewsdict)) contentview.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|-[namelabel]-|", options: nslayoutformatoptions( 0 ), metrics: nil, views: viewsdict)) contentview.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|-[emaillabel]-|", options: nslayoutformatoptions( 0 ), metrics: nil, views: viewsdict)) contentview.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|-[phonelabel]-|", options: nslayoutformatoptions( 0 ), metrics: nil, views: viewsdict)) } override func setselected(selected: bool, animated: bool) { super.setselected(selected, animated: animated) // configure view selected state } }
and using follows:
func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { var cell = importedcontactstvcell() cell.namelabel.text = "a" cell.emaillabel.text = "b" cell.phonelabel.text = "c" return cell }
their no prototype cells created on storyboard. missing please?
thanks in advance.
awakefromnib
not going called cell make entirely in code. should override initwithstyle:reuseidentifier:
, , put code in there. can still instantiate cell importedcontactstvcell()
since don't want of style choices. if you're using more few cells though, should using normal dequeue mechanism create cells.
Comments
Post a Comment