local MainScene = class("MainScene", cc.load("mvc").ViewBase) function MainScene:onCreate() local im = ccui.ImageView:create("HelloWorld.png")
self:addChild(im)
im:setPosition(,) local scene = self local list = {}
for i=, do
table.insert(list,i.."号位")
end
dump(list) local tableSize = cc.size(,)
local cellSize = cc.size(tableSize.width, )
local tv = cc.TableView:create(tableSize)
self:addChild(tv)
tv:setPosition(,)
tv:setScale(1.5) local function tableCellAtIndex(table, idx)
--print("tableCellAtIndex"..idx)
local cell = table:dequeueCell()
if cell then
--cell:removeAllChildren()
else
cell = cc.TableViewCell:create() local ly = ccui.Layout:create()
ly:setBackGroundColorType()
ly:setBackGroundColor({r = , g = , b = })
ly:setBackGroundColorOpacity()
local layout = ccui.LayoutComponent:bindLayoutComponent(ly)
layout:setSize({width = cellSize.width,height =cellSize.height-})
cell:addChild(ly) cell.oneItem= ccui.Text:create("","",)
cell.oneItem:setFontSize()
cell.oneItem:setfont
cell.oneItem:setColor(cc.c3b(,,))
cell:addChild(cell.oneItem,)
cell.oneItem:setPosition(,) cell.btn = ccui.Button:create("btn.png")
cell.btn:setAnchorPoint(cc.p(,))
cell:addChild(cell.btn,)
cell.btn:setSwallowTouches(false) local function btnClick(sender, state)
--print("btn "..cell.btn:getTag())
local event = {}
if state == then
event.name = "began"
tv.ScorllState = false
elseif state == then
event.name = "moved"
elseif state == then
event.name = "ended"
if tv.ScorllState == false then
print("btn click "..cell.btn:getTag())
end
else
event.name = "cancelled"
end print(event.name)
end
--cell.btn:addClickEventListener(btnClick)
cell.btn:addTouchEventListener(btnClick)
end cell.btn:setTag(idx+)
cell.oneItem:setString(list[idx+]) return cell
end
local function cellSizeForIndex(table, idx)
--print("cellSizeForIndex"..idx)
return cellSize.width, cellSize.height
end
local function numberOfCellsInTableView(table)
--print("numberOfCellsInTableView")
return #list
end local function tableDidScroll(table)
--print("tableDidScroll")
tv.ScorllState = true
end
tv:setDelegate()
tv:registerScriptHandler(cellSizeForIndex, cc.TABLECELL_SIZE_FOR_INDEX)
tv:registerScriptHandler(tableCellAtIndex, cc.TABLECELL_SIZE_AT_INDEX)
tv:registerScriptHandler(numberOfCellsInTableView, cc.NUMBER_OF_CELLS_IN_TABLEVIEW)
tv:registerScriptHandler(tableDidScroll, cc.SCROLLVIEW_SCRIPT_SCROLL) tv:reloadData() end return MainScene