diff --git a/lua/app/ui/main_city/main_city_ui.lua b/lua/app/ui/main_city/main_city_ui.lua index 0fc644e8..1c2487d9 100644 --- a/lua/app/ui/main_city/main_city_ui.lua +++ b/lua/app/ui/main_city/main_city_ui.lua @@ -272,6 +272,26 @@ function MainCityUI:initLeftRightBtns() if self.sideBarCellMap == nil then self.sideBarCellMap = {} end + self:recycleSideBarCells(self.leftSideBar) + self:recycleSideBarCells(self.rightSideBar) +end + +function MainCityUI:recycleSideBarCells(list) + local childList = list:getChildList() + if childList and #childList > 0 then + local count = #childList + for i = count, 1, -1 do + local child = childList[i] + local name = child:getName() + if name and name ~= "" then + child:setVisible(false) + self.sideBarCellMap[name] = child:getLuaComponent(name) + else + child:destroy() + table.remove(childList, i) + end + end + end end function MainCityUI:addSideBarCellComp(cellClassPath) @@ -280,6 +300,7 @@ function MainCityUI:addSideBarCellComp(cellClassPath) prefabObject:initWithPrefab(GConst.EMPTY_STRING, prefab) prefabObject:initPrefabHelper() prefabObject:genAllChildren() + prefabObject:setName(cellClassPath) return prefabObject:addLuaComponent(cellClassPath) end @@ -377,6 +398,7 @@ function MainCityUI:refreshRightBtns() else for k, v in ipairs(self.rightBarList) do v:setAnchoredPositionY(y) + v:setVisible(true) v:refresh() y = y - self.sideBarHeight - 2 end