zoukankan      html  css  js  c++  java
  • TableView+Button

    local MainScene = class("MainScene", cc.load("mvc").ViewBase)
    
    function MainScene:onCreate()
        
        local im = ccui.ImageView:create("HelloWorld.png")
        self:addChild(im)
        im:setPosition(200,200)
    
        local scene = self
    
        local list = {}
        for i=1,20 do
            table.insert(list,i.."号位")
        end
        dump(list)
    
    
        local tableSize = cc.size(500,800)
        local cellSize = cc.size(tableSize.width, 100)
        local tv = cc.TableView:create(tableSize)
        self:addChild(tv)
        tv:setPosition(500,300)
        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(1)
                ly:setBackGroundColor({r = 255, g = 0, b = 0})
                ly:setBackGroundColorOpacity(102)
                local layout = ccui.LayoutComponent:bindLayoutComponent(ly)
                layout:setSize({width = cellSize.width,height =cellSize.height-2})
                cell:addChild(ly)
    
                cell.oneItem= ccui.Text:create("","",30)
                cell.oneItem:setFontSize(30)
                cell.oneItem:setfont
                cell.oneItem:setColor(cc.c3b(0,0,0))
                cell:addChild(cell.oneItem,2)
                cell.oneItem:setPosition(50,50)
    
                cell.btn = ccui.Button:create("btn.png")
                cell.btn:setAnchorPoint(cc.p(0,0))
                cell:addChild(cell.btn,1)
                cell.btn:setSwallowTouches(false)
                
                local function btnClick(sender, state)
                    --print("btn    "..cell.btn:getTag())
                    local event = {}
                    if state == 0 then
                        event.name = "began"
                        tv.ScorllState = false
                    elseif state == 1 then
                        event.name = "moved"
                    elseif state == 2 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+1)
            cell.oneItem:setString(list[idx+1])
    
            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
  • 相关阅读:
    linux tcp调优
    nginx 代理http配置实例
    nginx代理socket tcp/udp
    C++对象数组初始化
    《大型网站技术架构》读书笔记
    内核空间、用户空间和虚拟地址(转)
    集群——LVS理论(转)
    Linux服务器集群系统(一)(转)
    从一个开发的角度看负载均衡和LVS(转)
    ubuntu下允许root用户ssh远程登录
  • 原文地址:https://www.cnblogs.com/mingfuqishi/p/10149847.html
Copyright © 2011-2022 走看看