From 2a8dd6bbcadf08ad6abe77a72b5043f064be6f35 Mon Sep 17 00:00:00 2001 From: chenxi Date: Fri, 12 May 2023 11:54:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E5=9F=8E=E8=B5=84=E6=BA=90=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/ui/main_city/main_city_ui.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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