table - Swift - using UITableView without a storyboard -
table - Swift - using UITableView without a storyboard -
i'm trying set tableview subview in viewcontroller. without using storyboard! i'm trying code, doesn't seem work , can't understand why.. code in tableview should created
func tableview(position: cgrect, allrecipes: [recipe]) -> uitableview { allow tableview: uitableview = uitableviewforallrecipes(style: uitableviewstyle.plain).tableview homecoming tableview; }
.
and tableviewcontroller (uitableviewforallrecipes)
class uitableviewforallrecipes: uitableviewcontroller { override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { var cell: uitableviewcell = uitableviewcell(style: uitableviewcellstyle.default, reuseidentifier: "cell") cell.textlabel.text = "ok" homecoming cell } override func numberofsectionsintableview(tableview: uitableview) -> int { println("nosit") homecoming 1 } override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { println("tv") homecoming 3 }
}
does see i'm doing wrong? doesn't seem print "nosit" , "tv", doesn't reach code.. didn't out of debugging also..
@swipesight right. reason why see empty tableview:
you create instance of uitableviewforallrecipes, tableview controller holds tableview , tableview's datasource , delegate. then grab tableview, add together subview, since tableview holds delegate weak reference, when quit tableview() func, tableviewcontroller released, since no more strong ref. when tableview beingness rendered, asks datasource, nil , empty table view.possible fix:
hold strong ref tableviewcontroller in parent view controller
e.g
func tableviewcontroller(position: cgrect, allrecipes: [recipe]) -> uitableviewforallrecipes { homecoming uitableviewforallrecipes(style: uitableviewstyle.plain) }
add property in parent view controller
var tableviewcontroller: uitableviewforallrecipes?
then in function phone call tableview
self.tableviewcontroller = self.tableviewcontroller(xxxx) self.view.addsubview(self.tableviewcontroller!.tableview)
uitableview table swift ios8 tableview
Comments
Post a Comment