iOS Swift - UITableViewCell Custom Subclass not displaying content -
i have uitableview i've created in uistoryboard has 2 dynamic prototype uitableviewcells:
the screenshot show have first uitableviewcell's style set subtitle, , second set custom label "tap add" in center. first has identifier of "cell" , second "addcell". i've set uitableviewcontroller (i've tried uitableview in uiviewcontroller), uitableviewcell subclass in swift , i've connected of outlets. however, when run simulator cell loaded , tappable, have not been able display content. (i've tried adding other controls, nothing appear when cell loaded. thing can change contentview's backgroundcolor.)
i have following swift code uitableviewcontroller:
import uikit class listtableviewcontroller: uitableviewcontroller { var listobjects: listobject[] = datamanager.instance.alllistobjects() listobject[] init(style: uitableviewstyle) { super.init(style: style) // custom initialization } init(coder adecoder: nscoder!) { super.init(coder: adecoder) } override func viewdidload() { super.viewdidload() self.tableview.registerclass(addlistobjecttableviewcell.classforcoder(), forcellreuseidentifier: "addcell") } @ibaction func editbuttonpressed(editbutton: uibarbuttonitem) { if (self.tableview.editing) { editbutton.title = "edit" self.tableview.setediting(false, animated: true) } else { editbutton.title = "done" self.tableview.setediting(true, animated: true) } } // #pragma mark - table view data source override func numberofsectionsintableview(tableview: uitableview?) -> int { return 1 } override func tableview(tableview: uitableview?, numberofrowsinsection section: int) -> int { return listobjects.count + 1 } override func tableview(tableview: uitableview!, cellforrowatindexpath indexpath: nsindexpath!) -> uitableviewcell! { let cellidentifier = (indexpath.row < listobjects.count) ? "cell" : "addcell" var cell = tableview.dequeuereusablecellwithidentifier(cellidentifier, forindexpath: indexpath) uitableviewcell if (indexpath.row < listobjects.count) { let currentlistobject : listobject = listobjects[indexpath.row] cell.textlabel.text = currentlistobject.name cell.detailtextlabel.text = currentlistobject.detail } else { cell = tableview.dequeuereusablecellwithidentifier(cellidentifier, forindexpath: indexpath) addlistobjecttableviewcell if (cell == nil) { cell = addlistobjecttableviewcell(style: uitableviewcellstyle.default, reuseidentifier: cellidentifier) } } return cell } override func tableview(tableview: uitableview!, didselectrowatindexpath indexpath: nsindexpath!) { if (indexpath.row < listobjects.count) { } else { self.performseguewithidentifier("addlistobjectshow", sender: self) } tableview.deselectrowatindexpath(indexpath, animated: true) } // override support conditional editing of table view. override func tableview(tableview: uitableview?, caneditrowatindexpath indexpath: nsindexpath?) -> bool { return (indexpath?.row < listobjects.count) ? true : false }}
i have following swift uitableviewcell:
import uikit class addlistobjecttableviewcell: uitableviewcell { @iboutlet var addlabel : uilabel init(style: uitableviewcellstyle, reuseidentifier: string) { super.init(style: style, reuseidentifier: reuseidentifier) // initialization code } override func awakefromnib() { super.awakefromnib() // initialization code } override func setselected(selected: bool, animated: bool) { super.setselected(selected, animated: animated) // configure view selected state }}
finally, here screenshot of simulator empty cell visible when selected:
i've double checked all of outlets connected, class names set in interface builder, i've registered class of uitableviewcell tableview, , seems configured correctly. possible bug? appreciated.
i believe has sizing in storyboard. seems likes default wider view , people including me (and judging storyboard view width, you) prefer having width set 'compact'.
in storyboard either try setting width/height any/any or in inspector labels inside cells scroll way down , play 'installed' checkbox , you'll notice has various options sizing class. if it's mine, you'll have first 'installed' 1 unchecked , second 1 sizing option checked. removed custom 'installed' , checked default 1 , moved labels place.
i don't believe have enough reputation post more 1 image or 2 links, wish explain mean easier.
Comments
Post a Comment