1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| local MainScene = class("MainScene", cc.load("mvc").ViewBase) function MainScene:onCreate() self.tableView2 = cc.TableView:create(cc.size(200, 200)) self.tableView2:setDirection(cc.SCROLLVIEW_DIRECTION_HORIZONTAL) self.tableView2:setPosition(cc.p(200, 200)) self.tableView2:setDelegate() self:addChild(self.tableView2) self.tableView2:registerScriptHandler(handler(self, self.scrollViewDidScroll) , cc.SCROLLVIEW_SCRIPT_SCROLL) self.tableView2:registerScriptHandler(handler(self, self.scrollViewDidZoom) , cc.SCROLLVIEW_SCRIPT_ZOOM) self.tableView2:registerScriptHandler(handler(self, self.tableCellTouched) , cc.TABLECELL_TOUCHED) self.tableView2:registerScriptHandler(handler(self, self.cellSizeForTable) , cc.TABLECELL_SIZE_FOR_INDEX) self.tableView2:registerScriptHandler(handler(self, self.tableCellAtIndex) , cc.TABLECELL_SIZE_AT_INDEX) self.tableView2:registerScriptHandler(handler(self, self.numberOfCellsInTableView) , cc.NUMBER_OF_CELLS_IN_TABLEVIEW) self.tableView2:reloadData() end function MainScene:scrollViewDidScroll(view) print("ScrollViewDidScroll") end function MainScene:scrollViewDidZoom(view) print("ScrollViewDidZoom") end function MainScene:tableCellTouched(table, cell) if nil == cell then return else print("cell touched at index: "..cell:getIdx()) end end function MainScene:cellSizeForTable(table, idx) return 60, 60 end function MainScene:tableCellAtIndex(table, idx) local strValue = string.format("%d", idx) local cell = table:dequeueCell() local label = nil if nil == cell then cell = cc.TableViewCell:create() label = cc.Label:createWithSystemFont(strValue, "Arial", 32) label:setPosition(cc.p(0, 0)) label:setAnchorPoint(cc.p(0, 0)) cell:addChild(label) label:setTag(123) else label = cell:getChildByTag(123) if label ~= nil then label:setString(strValue) end end return cell end function MainScene:numberOfCellsInTableView(table) return 20 end return MainScene
|