Thursday 15 July 2010

ios - tableView is nil when calling function from XIB -



ios - tableView is nil when calling function from XIB -

i have tableview working correctly. contents populated correctly. have couple of buttons in navigation bar filter content of tableview , reloaddata too. fine.

but i'm trying have custom tableview header, have buttons in there. created xib file , added tableview header.

mainviewcontroller.swft

func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? { var headerxib:uiview = nsbundle.mainbundle().loadnibnamed("headerview", owner: self, options: nil).first uiview var tableheader = uiview(frame: cgrectmake(0, 0, 300, 80)) tableheader.addsubview(headerxib) homecoming tableheader } // function i'm trying run func justreload(){ println("reload \(tableview)") tableview.reloaddata() }

everything fine far. created ibaction in xib swift file phone call function main view controller (which 1 tableview)

headerview.xib

@ibaction func touhcbb(sender: anyobject) { allow vc = mainviewcontroller() vc.justreload() }

so, here problem. println() in justreload() function shows tableview nil. causing error in reloaddata().

why nil if function called external xib file?

when seek phone call function iboutlet in same viewcontroller, works fine.

i appreciate if have hints or clues point me right direction. thanks!

open xib, , set class of file's owner mainviewcontroller:

mainviewcontrtoller.swift

class mainviewcontroller: uitableviewcontroller { // utilize ib connect button action method. @ibaction func touhcbb(sender: anyobject) { justreload() } func justreload(){ println("reload \(tableview)") tableview.reloaddata() } func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? { var headerxib:uiview = nsbundle.mainbundle().loadnibnamed("headerview", owner: self, options: nil).first uiview var tableheader = uiview(frame: cgrectmake(0, 0, 300, 80)) tableheader.addsubview(headerxib) homecoming tableheader } }

ios uitableview swift xib

No comments:

Post a Comment