当前位置:网站首页>cocos_ Lua listview loads too much data
cocos_ Lua listview loads too much data
2022-07-05 04:56:00 【Meteor spot】
establish QuickCell file
local QuickCell = class("QuickCell", function()
return ccui.Widget:create()
end)
-- self._data.wid default 100
-- self._data.hei default 50
-- self._data.anchor default {x=0, y=0}
-- self._data.tick_interval default 0.02
-- self._data.activeEvent default inview
-- self._data.createCell default nil
function QuickCell:ctor()
self._entered = false
self._active = true
end
function QuickCell:Create( data )
local cell = QuickCell.new()
if cell and cell:Init( data ) then
return cell
end
return nil
end
function QuickCell:Init( data )
self._data = data
local wid = self._data.wid or 100
local hei = self._data.hei or 50
local anchor = self._data.anchor or {x=0, y=0}
self:setContentSize( {width = wid, height = hei} )
self:setAnchorPoint( anchor )
self:Active()
return true
end
function QuickCell:Update( data )
local createCell = data.createCell
self._data.createCell = createCell
-- Perform the following exit , Easy to refresh immediately
self:Exit()
end
function QuickCell:Enter()
if self._entered then
return false
end
self._entered = true
local createCell = self._data.createCell
local wid = self._data.wid or 100
local hei = self._data.hei or 50
if not createCell then
return false
end
local cell = createCell()
if tolua.isnull(self) then
return
end
self:addChild( cell )
if not self._data.nobool then
cell:setAnchorPoint({x=0.5, y=0.5})
cell:setPosition({x=wid/2, y=hei/2})
end
end
function QuickCell:Exit()
if not self._entered then
return false
end
self._entered = false
self:removeAllChildren()
end
function QuickCell:Refresh()
if not self._active then
return false
end
local active = true
local activeEvent = self._data.activeEvent
if activeEvent then
active = activeEvent()
elseif self._data.eventX then
local viewSize = global.Director:getVisibleSize()
local pos = self:getWorldPosition()
local wid = self._data.wid or 100
local hei = self._data.hei or 50
active = not ( pos.x >= viewSize.width + wid or pos.x <= -wid )
else
local viewSize = global.Director:getVisibleSize()
local pos = self:getWorldPosition()
local wid = self._data.wid or 100
local hei = self._data.hei or 50
active = not ( pos.y >= viewSize.height + hei or pos.y <= -hei )
end
if active then
self:Enter()
else
self:Exit()
end
end
function QuickCell:Active()
self._active = true
local tick_interval = self._data.tick_interval or 0.02
self:stopAllActions()
schedule(self, function()
self:Refresh()
end, tick_interval)
end
function QuickCell:Sleep()
self._active = false
self:stopAllActions()
end
return QuickCell
Use in another file :
local QuickCell = requireUtil("QuickCell")
function ActivityLayer:InitUI()
local size = self.Panel_item:getContentSize()
-- self.ListView_left:removeAllChildren()
for i,v in pairs(self.needData) do
local item = self.ListView_left:getItem(i-1)
if not item then
local cell_data = {}
cell_data.wid = size.width
cell_data.hei = size.height
cell_data.createCell = function()
local cell = self:CreateCell(i,v)
return cell
end
item = QuickCell:Create(cell_data)
item:setName(i)
self.ListView_left:pushBackCustomItem(item)
end
item = UIGetChildByName(item, "item")
if item then -- Refresh data only
item = ui_delegate(item)
self:updateItem(item , v ,i, true)
end
end
self.ListView_left:setSwallowTouches(false)
self.ListView_left:forceDoLayout()
end
function ActivityLayer:CreateCell(index , v )
local item = self.Panel_item:cloneEx()
item:setVisible(true)
item:setName("item")
item = ui_delegate(item)
self:updateItem(item, v,index)
return item.nativeUI
end
function ActivityLayer:updateItem(item , data ,index,isUp )
local listView = item.ListView_icon
listView:setClippingType(0)
listView:setSwallowTouches(false) -- nesting listView Slide conflict resolution
if not isUp then -- Only modify the status without regenerating
listView:removeAllChildren()
end
local rewardata = data.reward
if rewardata and not isUp then
for i,v in pairs(rewardata) do
local item1 = self.Panel_item_icon:cloneEx()
local goods = GoodsItem:create({itemId=tonumber(v.itemId), count=tonumber(v.count), look=true})
goods:setAnchorPoint(cc.p(0,0))
goods:setItemTouchSwallow(false)
goods:setScale(0.8)
item1:getChildByName("Image_icon"):addChild(goods)
item1:setVisible(true)
listView:pushBackCustomItem(item1)
end
end
item.Image_lingqu:setVisible(false)
item.Button_go:addClickEventListener(function(sender)
end)
end
边栏推荐
- [groovy] closure (closure call is associated with call method | call () method is defined in interface | call () method is defined in class | code example)
- [ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
- 2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
- PR first time
- Leetcode word search (backtracking method)
- 中国针状焦行业发展研究与投资价值报告(2022版)
- AutoCAD -- dimension break
- 775 Div.1 B. integral array mathematics
- 中国AS树脂市场调研与投资预测报告(2022版)
- #775 Div.1 B. Integral Array 数学
猜你喜欢

django连接数据库报错,这是什么原因

Understand encodefloatrgba and decodefloatrgba
![[Business Research Report] top ten trends of science and technology and it in 2022 - with download link](/img/9f/4fc63fa7b0e9afc5dd638d4b599b2c.jpg)
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
![[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)](/img/1b/1fa2ebc9a6c5d271c9b39f5e508fb0.jpg)
[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)

UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存

XSS injection

【acwing】836. Merge sets

JVM 原理和流程简介

Thinking of 2022 American College Students' mathematical modeling competition
![[groovy] closure (closure as function parameter | code example)](/img/a6/a4ed401acfb61f85eb08daa15a8a80.jpg)
[groovy] closure (closure as function parameter | code example)
随机推荐
AutoCAD - Document Management
Recherche de mots pour leetcode (solution rétrospective)
Fluent objects and lists
[groovy] closure (closure as function parameter | code example)
Cocos progress bar progresstimer
中国聚氨酯硬泡市场调研与投资预测报告(2022版)
Basic knowledge points of dictionary
3dsmax common commands
Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
Download the details and sequence of the original data access from the ENA database in EBI
[ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
2021 electrician Cup - high speed rail traction power supply system operation data analysis and equivalent modeling ideas + code
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
SQLServer 存储过程传递数组参数
Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
mysql審計日志歸檔
Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas
Unity parallax infinite scrolling background