---创建tabView
            ---@param size {width:number,height:number}
            ---@param funcMap TabViewFuncMap
            ---@return TableView
            local function create_tableView(size, funcMap)
                local tableView = cc.TableView:create(size)
                tableView:setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL)
                tableView:setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN)
                tableView:setDelegate()
                tableView:setAnchorPoint(0, 1)
                tableView:registerScriptHandler(funcMap.NUMBER_OF_CELLS_IN_TABLEVIEW, cc.NUMBER_OF_CELLS_IN_TABLEVIEW)
                tableView:registerScriptHandler(funcMap.SCROLLVIEW_SCRIPT_SCROLL, cc.SCROLLVIEW_SCRIPT_SCROLL)
                tableView:registerScriptHandler(funcMap.TABLECELL_TOUCHED, cc.TABLECELL_TOUCHED)
                tableView:registerScriptHandler(funcMap.TABLECELL_SIZE_FOR_INDEX, cc.TABLECELL_SIZE_FOR_INDEX)
                tableView:registerScriptHandler(funcMap.TABLECELL_SIZE_AT_INDEX, cc.TABLECELL_SIZE_AT_INDEX)
                return tableView
            end


            local function createTabView(size)
                local function scrollViewDidScroll1(view)
                    -- print("=========  scrollViewDidScroll1 滚动事件")
                   
                end
                local function tableCellTouched(table, cell)
                    -- print("=========  tableCellTouched  单元格点击事件")
                end
                ---@param table TableView
                local function cellSizeForTable(table, idx)
                    -- print("=========  cellSizeForTable  单元格大小事件")
                    return 100, 100
                end
                ---@param table TableView
                local function tableCellAtIndex(table, idx)
                    local index = idx + 1
                    local tabel_cell = table:dequeueCell()
                    -- print("=========  tableCellAtIndex  单元格创建事件", index)
        
                    ---使用缓存池不使用分帧的方式
                    local function usePoolNoFenZhen()
                        local data = self.chat_data[index]
                        --初始化
                        if nil == tabel_cell then
                            tabel_cell = cc.TableViewCell:new()
                            local itemCom = self:get_chat_item_by_data(data, index)
                            tabel_cell:addChild(itemCom.view)
                        else
                            tabel_cell:removeAllChildren()
                            ---@type ChatListItem|ChatNotice
                            local itemCom = self:get_chat_item_by_data(data, index)
                            itemCom:update_all(data, self.channel)
                            tabel_cell:addChild(itemCom.view)
                        end
                        return tabel_cell
                    end
        
                    local tabel_cell = usePoolNoFenZhen()
                    return tabel_cell
                end
                local function numberOfCellsInTableView(table)
                    -- print("=========  numberOfCellsInTableView  单元格数量")
                    local dataLen = #self.chat_data
                    return dataLen
                end
        
                local funcMap = TabViewFuncMapSS()
                funcMap.NUMBER_OF_CELLS_IN_TABLEVIEW = numberOfCellsInTableView
                funcMap.SCROLLVIEW_SCRIPT_SCROLL = scrollViewDidScroll1
                funcMap.TABLECELL_TOUCHED = tableCellTouched
                funcMap.TABLECELL_SIZE_FOR_INDEX = cellSizeForTable
                funcMap.TABLECELL_SIZE_AT_INDEX = tableCellAtIndex
                local tableView = create_tableView(size, funcMap)
        
                return tableView
            end

 

posted on 2020-12-24 16:21  DMC-尼禄  阅读(295)  评论(0编辑  收藏  举报