ios - Creating static cells in Swift -
i'm trying create static cells in uitableviewcell. i've started adding 2 cells in interface builder , given them identifier title , news. i've created array these 2 identifiers , added cellforrowatindexpath. keep getting following error:
'unable dequeue cell identifier title - must register nib or class identifier or connect prototype cell in storyboard' the array
var menuitems = ["title", "news"] tableview delegate methods
override func numberofsectionsintableview(tableview: uitableview) -> int { // #warning potentially incomplete method implementation. // return number of sections. return 1 } override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { // #warning incomplete method implementation. // return number of rows in section. return 2 } override func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat { return 64 } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier(menuitems[indexpath.row], forindexpath: indexpath) as! uitableviewcell cell.backgroundcolor = uicolor(white: 0.2, alpha: 1.0) var bottomview: uiview = uiview(frame: cgrectmake(0, cell.frame.height-1, cell.frame.width, 1)) bottomview.backgroundcolor = uicolor(white: 0.2, alpha: 0.15) cell.contentview.addsubview(bottomview) return cell }
it seems have register uitableviewcell class manually cell. can achieve calling
tableview.registerclass(uitableviewcell.self, forcellreuseidentifier: menuitems[indexpath.row]) in either viewdidload() function of in cellforrowatindexpath function of uitableviewdatasource
Comments
Post a Comment