--[[ author:xuqian time:2020-03-09 16:30:58 数据格式和使用方式 后面想做成通用的 这个先这样 以后优化 后面根据使用情况 cell路径 大小 位置 都可配置 function UITemplate:initMainCellCallBack(cellTable,data,index) logging.warn(LTAG.CRIT, "initMainCellCallBack ", data.desc) cellTable.lab_Main01.text = data.desc cellTable.Check.gameObject:SetActive(true) cellTable.UnCheck.gameObject:SetActive(false) end function UITemplate:initSubCellCallBack(cellTable,data,index) logging.warn(LTAG.CRIT, "initSubCellCallBack ", data.desc) cellTable.lab_Zhang01.text = data.desc end function UITemplate:clickMainCellCallBack (cellTable,target,data,index,isFold) logging.warn(LTAG.CRIT, "clickMainCellCallBack ", data.desc) cellTable.lab_Main01.text = data.desc cellTable.Check.gameObject:SetActive(isFold) cellTable.UnCheck.gameObject:SetActive(not isFold) end function UITemplate:clickSubCellCallBack (cellTable,target,data,index) logging.warn(LTAG.CRIT, "clickSubCellCallBack ", data.desc) end function UITemplate:OpenCommonFoldView( ) local UICommonFoldView = require("View/Common/UICommonFoldView") local context = {} context.mainData = {} context.mainData[1] = {desc="主一",subData={{desc="主一副一"},{desc="主一副二"},{desc="主一副三"}}} context.mainData[2] = {desc="主二",subData={{desc="主二副一"},{desc="主二副二"},{desc="主二副三"}}} context.mainData[3] = {desc="主三",subData={{desc="主三副一"},{desc="主三副二"},{desc="主三副三"}}} context.parentView = self self.root:OpenView(GetViewClass("Common/UICommonFoldView",context), nil, nil, nil) end ]] local UICommonFoldView = UIViewClass() local CellType = { Main = 1, Sub = 2, } function UICommonFoldView:OnOpened(context) self.tempSubIndex = {} self.extraIndex = 0 self.mainData = context.mainData self.parentView = context.parentView for i,v in ipairs(context.mainData) do v.isUnfold = false v.type = CellType.Main self.scroll_Main:AddData(v,0) end end function UICommonFoldView:UnFold(cellTable, mainData, index) mainData.isUnfold = true UIUtils.SetActive(cellTable.Check.gameObject, true) UIUtils.SetActive(cellTable.UnCheck.gameObject, false) for i,v in ipairs(mainData.subData) do v.type = CellType.Sub self.scroll_Main:InsertData(index+i, v, 1) table.insert(self.tempSubIndex, index + i) end self.extraIndex = #self.tempSubIndex end function UICommonFoldView:Fold(cellTable, mainData, index) mainData.isUnfold = false UIUtils.SetActive(cellTable.UnCheck.gameObject, true) UIUtils.SetActive(cellTable.Check.gameObject, false) local count = #mainData.subData for i = 1, count do self.scroll_Main:RemoveIndex(1 + index) end self.tempSubIndex = {} if self.selectIndex > index then self.selectIndex = self.selectIndex - count end end function UICommonFoldView:OnCellInit(scrollRect, index, cellTable, data) if data.type == CellType.Main then self.parentView:initMainCellCallBack(scrollRect, cellTable, data, index) if data.isUnfold then if data.subData then self:Fold(cellTable, data, index) end end else UIUtils.SetActive(cellTable.UnCheck.gameObject, true) UIUtils.SetActive(cellTable.Check.gameObject, false) self.parentView:initSubCellCallBack(scrollRect, cellTable,data,index) end end function UICommonFoldView:OnCellClicked(scrollRect, index, cellTable, target, data) if data.type == CellType.Main then local lastIndex = self.selectIndex self.selectIndex = index if lastIndex then scrollRect:UpdateIndex(lastIndex) end else for i,v in ipairs(self.tempSubIndex) do scrollRect:UpdateIndex(v) end cellTable.Check.gameObject:SetActive(true) cellTable.UnCheck.gameObject:SetActive(false) end if data.type == CellType.Main then if data.subData then if data.isUnfold then self:Fold(cellTable, data, self.selectIndex) else self:UnFold(cellTable, data, self.selectIndex) end end self.parentView:clickMainCellCallBack(scrollRect, cellTable, target, data, self.selectIndex) else self.parentView:clickSubCellCallBack(scrollRect, cellTable, target, data, self.selectIndex) end end return UICommonFoldView