例如用UIListVIew做邮件系统,当阅读邮件后删除邮件,有新邮件时添加邮件
UIListView是通过初始化显示个数和设置item总个数来控制item显示的 如红色部分
通过蓝色部分控制UIListView更新, 问:如何控制item显示个数?
local nCount = 0
local listView = UIListView:create()
listView:setTouchEnable(true)
listView:setSize(CCSizeMake(240, 130))
listView:setPosition(ccp(100,100))
local listWidth = listView:getRect().size.width
local listHeight = listView:getRect().size.height
for i = 0,8 do
local textButton = UIButton:create()
textButton:setTouchEnable(true)
textButton:loadTextures("cocosgui/backtotoppressed.png", "cocosgui/backtotopnormal.png", "")
textButton:setPosition(ccp(0, 0))
listView:addChild(textButton)
end
local function eventHandler(eventType)
if eventType == "initChild" then
elseif eventType == "updateChild" then
local index = listView:getUpdateDataIndex()
if index < 0 or index >= listView:getDataLength() then
listView:setUpdateSuccess(false)
else
local textbutton =listView:getUpdateChild()
textbutton:setText(string.format("object_%d",index))
listView:setUpdateSuccess(true)
end
end
end
listView:registerEventScript(eventHandler)
listView:initChildWithDataLength(20)
uiLayer:addWidget(listView)