cocos2dx-2.2.2 + lua
Every time when I called removeAllChildren() to remove widgets that have been added into a scrollview ,It could not work properly. after removeAllChildren() been called,I could still see some widget that should have been removed shown in the scrollview .
But,If I call removeChildByTag() to remove those widget one by one, It works well.
Should I call any other function ,after I call removeAllChildren?
I use the testlus/CocoStudioGUITest/UIScrollViewVerticalTest to verify. I add the follow codes at the end of UIScrollViewVerticalTest:initExtend()
local entry = nil local scheduler = CCDirector:sharedDirector():getScheduler() local function update(dt) scrollView:removeAllChildren() scheduler:unscheduleScriptEntry(entry) end entry = scheduler:scheduleScriptFunc(update, 0, false)
The result was all the widgets were removed.
Can you give me the related codes?
@samuele3hu
I found that not only ScrollView but ListView too.
This is my code add items into a listview:
function __testlayer.LoadItems(obj,itemIdxList)
for idx = 1,#itemIdxList do
local TestItem = TestItem.new(idx)
–egNode() returns GUIReader:shareReader():widgetFromJsonFile(jsonFile)
obj._ListView:pushBackCustomItem(TestItem:egNode())
end
end
after call LoadItems() Listview shown as load.jpg
This is how I clear items before,and not works well
function __testlayer.clearItems(obj)
obj._ListView:removeAllItems()
end
after call clearItems() Listview shown as clear.jpg
This is how I clear items now:
function __testlayer.clearItems(obj)
for idx = 1,#itemIdxList do
local item = obj._ListView:getItem(idx-1)
obj._ListView:removeChildByTag(item:getTag(),true)
end
obj._ListView:removeAllItems()
end