------------------------------- CCListViewDynamic ---------------------------------------- cc.exports.CCListViewDynamic = class("CCListViewDynamic"); function CCListViewDynamic:ctor() self:_init(); end; function CCListViewDynamic:_init() -- 存储list可能使用的所有item数据 self.mBaseList = {}; -- 存储现在正在显示的所有item数据,其内容皆来自mBaseList self.mUseSortList = {}; -- 实际存储的ui列表 self.mShowItemList = {}; -- 过滤函数指针,传入对应item数据,返回true则过滤不显示 self.mFiltFunc = nil; -- 处理单个item的函数指针 self.mDealItemFunc = nil; -- 排序函数 self.mSortFunction = nil; -- 实际的滑动ui,必须为一个scrollview控件,并且滑动方向只能是垂直或水平 self.mListView = nil; -- 预先记录每列item的所在范围 self.mItemRangeRecorder = {}; -- 当前显示的最大最小列下标 self.mLastStarCol = nil; self.mLastEndCol = nil; -- 触摸事件相关,通过监听scrollview本身,获取相应坐标,在找出对应注册item实现触摸响应,一般不使用 self.mWidgetTouchEvents = {}; self.mBeganHitRect = nil; self.mHitCbfun = nil; end -- 释放列表内所有内容 function CCListViewDynamic:release() if self.mShowItemList then for _, v in pairs(self.mShowItemList) do v.item:removeFromParent(); end self.mShowItemList = {}; end self:_init(); --if self.mTouchScheduleId then -- local sharedScheduler = cc.Director:getInstance():getScheduler(); -- sharedScheduler:unscheduleScriptEntry(self.mTouchScheduleId); -- self.mTouchScheduleId = nil; --end end -- 添加新的item function CCListViewDynamic:addItem(pKey, pInfo) self.mBaseList[pKey] = {}; self.mBaseList[pKey].info = pInfo; self.mBaseList[pKey].nowIndex = -1; self.mBaseList[pKey].isInit = false; self.mBaseList[pKey].node = nil; return self.mBaseList[pKey]; end -- 移除item function CCListViewDynamic:removeItem(pInfoKey) self.mBaseList[pInfoKey] = nil; end -- 移除多个item function CCListViewDynamic:removeItems(pInfoKeyList) for _, key in pairs(pInfoKeyList) do self:removeItem(key); end end -- 单独更新一个item function CCListViewDynamic:refreshItem(pKey) local item = self.mBaseList[pKey].node; local info = self.mBaseList[pKey].info; if item then self.mDealItemFunc(item, info, self.mBaseList[pKey], self); end end -- 判断一个item是否在显示范围内 function CCListViewDynamic:isInWinSize(addItem) local innScPos; if self.mIsVertical then innScPos = self.mListView:getInnerContainer():getPositionY(); else innScPos = self.mListView:getInnerContainer():getPositionX(); end if innScPos > addItem.showScMin and innScPos < addItem.showScMax then return true; else return false; end end -- 获取当前正在使用列表 function CCListViewDynamic:getUseList() local srlist = {}; for _, v in pairs(self.mUseSortList) do srlist[#srlist + 1] = v; end return srlist; end -- 获取顺序下标的item相关数据 function CCListViewDynamic:getItemByIndex(pIndex) if self.mUseSortList[pIndex] then return self.mUseSortList[pIndex]; end end -- 获取listId的item相关数据 function CCListViewDynamic:getBaseListData(listId) return self.mBaseList[listId]; end -- 根据info属性表内容,找出相应item的ui并返回 function CCListViewDynamic:getItemUiByCustomKey(keyName, keyValue) for _, v in pairs(self.mUseSortList) do if v.info[keyName] == keyValue then if v.node and self:isInWinSize(v) then return v.node; end break; end end end -- 设置触摸相关 function CCListViewDynamic:_setTouchEnabled() local function checkHit(checkPos) local columnChilds = self.mListView:getChildren(); for _, row in pairs(columnChilds) do local itemName = row; local eventList; if self.mWidgetTouchEvents[itemName] then eventList = self.mWidgetTouchEvents[itemName].events; end if eventList then local function getLastTouchHitRect(pWidget) local rsize = pWidget:getContentSize(); local widgetWordPos = pWidget:getParent():convertToWorldSpace(cc.p(pWidget:getPosition())); local inPos = cc.p(widgetWordPos.x, widgetWordPos.y); local bbox = ccui.Helper:convertBoundingBoxToScreen(pWidget); local inRx = inPos.x - bbox.width * pWidget:getAnchorPoint().x; local inRy = inPos.y - bbox.height * pWidget:getAnchorPoint().y; local hitRect = cc.rect(inRx, inRy, bbox.width, bbox.height); --print("hitRect:" .. inRx .. "," .. inRy .. "," .. rsize.width .. "," .. rsize.height) if cc.rectContainsPoint(hitRect, checkPos) then return hitRect; end end local function checkCallBack(list) for _, v in ipairs(list) do local wrapEvUi = v.eventUi; local callBack = v.cbFunc; local hitRect = getLastTouchHitRect(wrapEvUi); if hitRect then return hitRect, callBack; end end end local hitRect, callBack = checkCallBack(eventList); if hitRect and callBack then return hitRect, callBack; end end end return nil; end self.mListView:addEventListener( function (sender, stype) -- UIScrollView.h中EventType.CONTAINER_MOVED的enum值为9 if stype == 9 then self:_dealSortListCreate(); end end ) -- 记录一开始的触摸区域,并返回该注册地方的响应函数,如果结束触摸还在区域中,才执行响应函数 self.mListView:onTouch( function (event) if event.name == "began" then local beganPos = self.mListView:getTouchBeganPosition(); local rect, cbfun = checkHit(beganPos); self.mBeganHitRect = rect; self.mHitCbfun = cbfun; elseif event.name == "moved" then if self.mBeganHitRect then --local movePos = self.mListView:getTouchMovePosition(); --if not cc.rectContainsPoint(self.mBeganHitRect, movePos) then -- self.mBeganHitRect = nil; -- self.mHitCbfun = nil; --end end elseif event.name == "ended" then if self.mHitCbfun then local beganPos = self.mListView:getTouchBeganPosition(); local endPos = self.mListView:getTouchEndPosition(); local absY = math.abs(beganPos.y - endPos.y); if absY < self:_getBaseItemSize().height * 0.2 then if cc.rectContainsPoint(self.mBeganHitRect, endPos) then self.mHitCbfun(event); self.mBeganHitRect = nil; self.mHitCbfun = nil; end end end elseif event.name == "cancelled" then if self.mBeganHitRect then --local movePos = self.mListView:getTouchMovePosition(); --if not cc.rectContainsPoint(self.mBeganHitRect, movePos) then -- 通过触摸开关达到停止本次触摸流程的目的 self.mListView:setTouchEnabled(false); self.mListView:setTouchEnabled(true); self.mHitCbfun = nil; self.mBeganHitRect = nil; --end end end end ) end -- 注册触摸事件,响应为listview本身 -- 基于一个item中的ui部件区域,由于触摸事件是listview响应,所以这个ui的交互性必须为false -- 越后注册的,优先级越高 function CCListViewDynamic:registerTouchByItemWidget(pItem, pEventUi, pCbFunc) if not self.mWidgetTouchEvents[pItem] then self.mWidgetTouchEvents[pItem] = {}; end local itrList = self.mWidgetTouchEvents[pItem]; if not itrList.events then itrList.events = {}; end local inx; for ii, v in ipairs(itrList.events) do if v.eventUi == pEventUi then inx = ii; break; end end if not inx then inx = 1; local insertTable = {}; table.insert(itrList.events, inx, insertTable) itrList.events[inx].eventUi = pEventUi; end itrList.events[inx].cbFunc = pCbFunc; end function CCListViewDynamic:unregisterTouchByItemWidget(pItem, pEventUi) if self.mWidgetTouchEvents[pItem] then local itrList = self.mWidgetTouchEvents[pItem]; local inx; for ii, v in ipairs(itrList.events) do if v.eventUi == pEventUi then inx = ii; break; end end if inx then table.remove(itrList.events, inx); end end end -- 创建实际的ui function CCListViewDynamic:_createShowItem(showIndex) local item; if self.mShowItemList[showIndex] then item = self.mShowItemList[showIndex].item; else item = require(self.mBaseItem):create().root; self.mShowItemList[showIndex] = {}; self.mShowItemList[showIndex].item = item; self.mShowItemList[showIndex].nowIndex = -1; self.mShowItemList[showIndex].key = nil; end return item; end -- 获取基本item的size,就是获取showitemlist中的第一个,如果没有则创建一个 function CCListViewDynamic:_getBaseItemSize() if not self.mShowItemList[1] then self:_createShowItem(1); end return self.mShowItemList[1].item:getContentSize(); end -- 初始化函数,使用必调 -- pListView 被使用的列表ui,必须是scrollview控件 -- pList 被使用的列表数据,根据这个初始化item的数量 -- pBaseItem 单个item的资源 -- pDealItemFunc 处理单个item的函数指针 -- pSortFunc 排序函数,可为空 -- pFiltFunc 过滤函数,可为空 function CCListViewDynamic:initWithList(pListView, pList, pBaseItem, pDealItemFunc, pSortFunc, pFiltFunc) self.mListView = pListView; self.mListView.creator = self self.mListData = pList self.mDealItemFunc = pDealItemFunc; self.mBaseItem = pBaseItem; self.mListView:setBounceEnabled(true); -- 滑动层是垂直或是水平的,保存起来 if self.mListView:getDirection() == ccui.LayoutType.VERTICAL then self.mIsVertical = true; else self.mIsVertical = false; end -- 通过宽高获取应初始化item的个数(可见的列数+1 * 每列的个数) local scwidth = self.mListView:getContentSize().width; local scheight = self.mListView:getContentSize().height; self.mListView:setInnerContainerSize(cc.size(scwidth, scheight)); local itemSize = self:_getBaseItemSize(); if self.mIsVertical then local showWidth = math.floor((scwidth + 1)/itemSize.width) + 1; local showHeightAdd = math.ceil((scheight)/itemSize.height); for i = 1, showWidth * showHeightAdd do local bitem = self:_createShowItem(i); self.mListView:addChild(bitem); end else local showWidth = math.floor((scwidth + 1)/itemSize.width); local showHeightAdd = math.ceil((scheight)/itemSize.height) + 1; for i = 1, showWidth * showHeightAdd do local bitem = self:_createShowItem(i); self.mListView:addChild(bitem); end end for listIndex, info in pairs(pList or {}) do self:addItem(listIndex, info); end if pSortFunc then local function sortIt(a, b) return pSortFunc(a.info, b.info); end self.mSortFunction = sortIt; end self.mFiltFunc = pFiltFunc; self:refreshView(); self:_setTouchEnabled(); end -- 计算要显示哪些item,并且调用mDealItemFunc,传入该item相关的数据 function CCListViewDynamic:_dealSortListCreate() local nowInnScVar; if self.mIsVertical then nowInnScVar = self.mListView:getInnerContainer():getPositionY(); else nowInnScVar = self.mListView:getInnerContainer():getPositionX(); end local isInverted; if nowInnScVar - self.mlastInnScVar >= 0 then isInverted = true; else isInverted = false; end local function dropItemByIndex(nowIndex) if self.mUseSortList[nowIndex].isInit then self.mUseSortList[nowIndex].isInit = false; self.mUseSortList[nowIndex].node = nil; for kk, v in ipairs (self.mShowItemList) do if v.nowIndex == nowIndex then printInfo("dropItemByIndex:" .. tostring(nowIndex) .. ",key:" .. tostring(kk)) v.nowIndex = -1; break; end end end end local function initItemByIndex(wrapInx, wrapList) local showInx = wrapInx; local nowIndex = wrapList[wrapInx]; local showItr = self.mShowItemList[showInx]; if not showItr then return; end while showItr.nowIndex ~= -1 do showInx = showInx + 1; if showInx > #self.mShowItemList then showInx = 1; end showItr = self.mShowItemList[showInx] if showInx == wrapInx and showItr.nowIndex ~= -1 then --print("self.mShowItemList full:"); --printTable(self.mShowItemList); return; end end if showItr and not self.mUseSortList[nowIndex].isInit then if showItr.nowIndex and showItr.nowIndex > 0 then if not self.mUseSortList[showItr.nowIndex] then -- 之前的标记已被删除 showItr.nowIndex = -1; else -- 如果之前显示item中有标记,则要删除掉供后面刷出的item使用 dropItemByIndex(showItr.nowIndex, true); end end showItr.item:setPosition(cc.p(self.mUseSortList[nowIndex].positionX, self.mUseSortList[nowIndex].positionY)); printInfo("init:" .. tostring(nowIndex)) self.mDealItemFunc(showItr.item, self.mUseSortList[nowIndex].info, self.mUseSortList[nowIndex], self); showItr.nowIndex = nowIndex; self.mUseSortList[nowIndex].node = showItr.item; self.mUseSortList[nowIndex].isInit = true; else --print("init failed:", tostring(showItr), ",", wrapInx) --print("init failed:", self.mUseSortList[nowIndex].isInit) end end local innScPos; if self.mIsVertical then innScPos = self.mListView:getInnerContainer():getPositionY(); else innScPos = self.mListView:getInnerContainer():getPositionX(); end local isInWin = false; local starCol; local endCol = #self.mItemRangeRecorder; for ii, v in ipairs(self.mItemRangeRecorder) do if innScPos >= v.showScMin and innScPos <= v.showScMax then if not starCol then starCol = ii; isInWin = true; end else if isInWin then endCol = ii - 1; break; end end end if starCol == nil then starCol = endCol; end -- 比较前后两个显示的列,把不在屏幕中的删除初始化标记 if self.mLastStarCol and self.mLastEndCol then local cmpTmp = self.mLastStarCol; while (cmpTmp < starCol) do local tgDropCol = self.mItemRangeRecorder[cmpTmp].colInxs; for dropI = 1, #tgDropCol do if self.mUseSortList[tgDropCol[dropI]] then dropItemByIndex(tgDropCol[dropI]); end end cmpTmp = cmpTmp + 1; end local cmpTmp = self.mLastEndCol; while (cmpTmp > endCol) do local tgDropCol = self.mItemRangeRecorder[cmpTmp].colInxs; for dropI = 1, #tgDropCol do if self.mUseSortList[tgDropCol[dropI]] then dropItemByIndex(tgDropCol[dropI]); end end cmpTmp = cmpTmp - 1; end end self.mlastInnScVar = nowInnScVar; if self.mLastStarCol and self.mLastEndCol and self.mLastStarCol == starCol and self.mLastEndCol == endCol then -- 标记一样直接退出,不做后续工作 return; end self.mLastStarCol = starCol; self.mLastEndCol = endCol; -- 根据前面标记 顺序提取出要遍历的下标,加入遍历列表中,然后做初始化显示工作 local wrapList = {}; for i = self.mLastStarCol, self.mLastEndCol do local cols = self.mItemRangeRecorder[i].colInxs; for j = 1, #cols do table.insert(wrapList, cols[j]); end end --printTable(wrapList) local wpBg = 1; local wpEnd = #wrapList; for wrapInx = wpBg, wpEnd do local nowIndex = wrapList[wrapInx]; if not self.mUseSortList[nowIndex] then break; end --print("ready for init:", nowIndex) initItemByIndex(wrapInx, wrapList); end end -- 移动列表到顶部 function CCListViewDynamic:scrollToTop() if self.mIsVertical then local innH = self.mListView:getInnerContainerSize().height; local scH = self.mListView:getContentSize().height; self.mListView:getInnerContainer():setPositionY(scH - innH); else local innH = self.mListView:getInnerContainerSize().width; local scH = self.mListView:getContentSize().width; self.mListView:getInnerContainer():setPositionX(scH - innH); end self:_dealSortListCreate(); end -- 移动列表到指定ID的item function CCListViewDynamic:scrollToItemByListId(listId) local cldata = self.mBaseList[listId]; if cldata then local itemHeight; local itemWidth; local itSize = self:_getBaseItemSize(); itemHeight = itSize.height; itemWidth = itSize.width; if self.mIsVertical then local setHeight = cldata.showScMax - itemHeight; if setHeight > 0 then setHeight = 0; end self.mListView:getInnerContainer():setPositionY(setHeight); else local setHeight = cldata.showScMax - itemWidth; if setHeight > 0 then setHeight = 0; end self.mListView:getInnerContainer():setPositionX(setHeight); end self:_dealSortListCreate(); end end -- 刷新页面,每次mUseSortList被改变后,都要调用 function CCListViewDynamic:refreshView() -- 记录上次初始化的item,如果还在窗口中,则不重复初始化 local updateHelperList = {} for _, v in pairs(self.mUseSortList) do if v.isInit then updateHelperList[v] = clone(v); updateHelperList[v].oldInx = v.nowIndex; end end --for _, v in pairs(self.mUseSortList) do --v.isInit = false; --v.node = nil; --v.nowIndex = -1; --end self.mUseSortList = {}; for baseIndex, v in pairs(self.mBaseList) do if not self.mFiltFunc then table.insert(self.mUseSortList, v); elseif self.mFiltFunc(v.info) then table.insert(self.mUseSortList, v); end end if self.mSortFunction then --table.sort(self.mUseSortList, self.mSortFunction); -- 为了排序稳定性 改为手动排序 local newList = {}; newList[1] = self.mUseSortList[1]; for baseIndex, v in ipairs(self.mUseSortList) do if baseIndex ~= 1 then local len = #newList; local isBreak = false; for i = len, 1, -1 do if self.mSortFunction(newList[i], v) then for j = len + 1, i + 1, -1 do newList[j] = newList[j - 1] end newList[i + 1] = v; isBreak = true; break; end end if not isBreak then for j = len + 1, 2, -1 do newList[j] = newList[j - 1] end newList[1] = v; end end end self.mUseSortList = newList; end local insetList = {}; local newSortList = {}; -- 头尾特殊处理 local headNode = insetList[0]; local tailNode = insetList[#self.mUseSortList + 1]; if headNode then for k, v in ipairs (headNode) do newSortList[#newSortList + 1] = v; end end for i = 1, #self.mUseSortList do newSortList[#newSortList + 1] = self.mUseSortList[i]; if insetList[i] then for k, v in ipairs(insetList[i]) do newSortList[#newSortList + 1] = v; end end end if tailNode then for k, v in ipairs(tailNode) do newSortList[#newSortList + 1] = v; end end self.mUseSortList = newSortList; self:_calcLayout(); if self.mIsVertical then self.mlastInnScVar = self.mListView:getInnerContainer():getPositionY(); else self.mlastInnScVar = self.mListView:getInnerContainer():getPositionX(); end local itemSize = self:_getBaseItemSize(); --for _, v in pairs (self.mShowItemList) do -- v.nowIndex = -1; -- v.item:setPosition(cc.p(-itemSize.width, -itemSize.height)); --end local updateShowItem = {}; for nowIndex = 1, #self.mUseSortList do local v = self.mUseSortList[nowIndex]; local showItem; if updateHelperList[v] and self:isInWinSize(v) then for _, vv in pairs (self.mShowItemList) do if vv.nowIndex == updateHelperList[v].oldInx then showItem = vv; break; end end end if not showItem then v.isInit = false; v.node = nil; else updateShowItem[showItem] = nowIndex; end end for _, vv in pairs (self.mShowItemList) do if updateShowItem[vv] then local nowIndex = updateShowItem[vv] vv.nowIndex = nowIndex --print("update:" .. vv.nowIndex); vv.item:setPosition(cc.p(self.mUseSortList[nowIndex].positionX, self.mUseSortList[nowIndex].positionY)); else vv.nowIndex = -1; vv.item:setPosition(cc.p(-itemSize.width, -itemSize.height)); end end self.mLastStarCol = nil; self.mLastEndCol = nil; self:_dealSortListCreate(); end -- 预计算scrollview滑动区域大小,并且算出每个item的坐标位置,以及所在显示范围 function CCListViewDynamic:_calcLayout() local listSize = self.mListView:getContentSize(); local pListIndex = 0; local pLastRowWidth = 0; local pLastRowItem = nil; self.mItemRangeRecorder = {}; for nowIndex = 1, #self.mUseSortList do self.mUseSortList[nowIndex].nowIndex = nowIndex; local itemHeight; local itemWidth; local itSize = self:_getBaseItemSize(); itemHeight = itSize.height; itemWidth = itSize.width; if self.mIsVertical then local listViewWidth = 0; listViewWidth = listSize.width; local nextRowItem = pLastRowItem; local nextListIndex = pListIndex; local nextLastRowWidth = pLastRowWidth; local rowRemainWidth; rowRemainWidth = listViewWidth - nextLastRowWidth - itemWidth; local lastPosY = 0; if rowRemainWidth <= 0 then if nextRowItem then lastPosY = nextRowItem.positionY end nextRowItem = nil; nextLastRowWidth = 0; end if nextRowItem == nil then nextRowItem = {}; nextRowItem.positionY = lastPosY - itemHeight; nextListIndex = nextListIndex + 1; end self.mUseSortList[nowIndex].positionX = nextLastRowWidth; self.mUseSortList[nowIndex].positionY = nextRowItem.positionY; nextLastRowWidth = nextLastRowWidth + itemWidth; -- 更新参数值后再次进入循环 pListIndex = nextListIndex; pLastRowWidth = nextLastRowWidth; pLastRowItem = nextRowItem; else local hItemCount = math.floor(listSize.height / itemHeight); local allItemCount = #self.mUseSortList; local lineCount = math.ceil(allItemCount / hItemCount); local lastLineCount = allItemCount % hItemCount; local listViewWidth = lineCount * itemWidth + 1; ----------------- local nextRowItem = pLastRowItem; local nextListIndex = pListIndex; local nextLastRowWidth = pLastRowWidth; local rowRemainWidth; rowRemainWidth = listViewWidth - nextLastRowWidth - itemWidth; local lastPosY = 0; if rowRemainWidth <= 0 then if nextRowItem then lastPosY = nextRowItem.positionY end nextRowItem = nil; nextLastRowWidth = 0; end if nextRowItem == nil then nextRowItem = {}; nextRowItem.positionY = lastPosY - itemHeight; nextListIndex = nextListIndex + 1; end self.mUseSortList[nowIndex].positionX = nextLastRowWidth; self.mUseSortList[nowIndex].positionY = nextRowItem.positionY; nextLastRowWidth = nextLastRowWidth + itemWidth; -- 更新参数值后再次进入循环 pListIndex = nextListIndex; pLastRowWidth = nextLastRowWidth; pLastRowItem = nextRowItem; end end if self.mIsVertical then local icSize = self.mListView:getInnerContainerSize(); -- 最后一个item的y坐标等同于要设置的innercontainer高度 local innHeight = 0; if #self.mUseSortList > 0 then innHeight = -self.mUseSortList[#self.mUseSortList].positionY; end self.mListView:setInnerContainerSize(cc.size(icSize.width, innHeight)); else local itSize = self:_getBaseItemSize(); local itemHeight = itSize.height; local itemWidth = itSize.width; local icSize = self.mListView:getInnerContainerSize(); local hItemCount = math.floor(listSize.height / itemHeight); local allItemCount = #self.mUseSortList; local lineCount = math.ceil(allItemCount / hItemCount); local lastLineCount = allItemCount % hItemCount; self.mListView:setInnerContainerSize(cc.size(lineCount * itemWidth, listSize.height)); end for nowIndex = 1, #self.mUseSortList do local innerSize = self.mListView:getInnerContainerSize(); self.mUseSortList[nowIndex].positionY = self.mUseSortList[nowIndex].positionY + innerSize.height; local itemHeight; local itemWidth; local itSize = self:_getBaseItemSize(); itemHeight = itSize.height; itemWidth = itSize.width; local listSize = self.mListView:getContentSize(); -- 根据不同滑动方向计算出这个item在哪段范围显示 local tailVar; local tailCmp; local innVar; if self.mIsVertical then tailVar = itemHeight; tailCmp = listSize.height; innVar = innerSize.height; self.mUseSortList[nowIndex].showScMin = tailCmp - innVar + (innVar - tailCmp - self.mUseSortList[nowIndex].positionY - tailVar); self.mUseSortList[nowIndex].showScMax = tailCmp - innVar + (innVar - self.mUseSortList[nowIndex].positionY); else tailVar = itemWidth; tailCmp = listSize.width; innVar = innerSize.width; self.mUseSortList[nowIndex].showScMin = tailCmp - innVar + (innVar - tailCmp - self.mUseSortList[nowIndex].positionX - tailVar); self.mUseSortList[nowIndex].showScMax = tailCmp - innVar + (innVar - self.mUseSortList[nowIndex].positionX); end -- 把同范围显示的item合并成一列 if self.mIsVertical then local reInx = #self.mItemRangeRecorder + 1; if #self.mItemRangeRecorder == 0 or self.mItemRangeRecorder[#self.mItemRangeRecorder].showScMin ~= self.mUseSortList[nowIndex].showScMin or self.mItemRangeRecorder[#self.mItemRangeRecorder].showScMax ~= self.mUseSortList[nowIndex].showScMax then self.mItemRangeRecorder[reInx] = {}; self.mItemRangeRecorder[reInx].showScMin = self.mUseSortList[nowIndex].showScMin self.mItemRangeRecorder[reInx].showScMax = self.mUseSortList[nowIndex].showScMax self.mItemRangeRecorder[reInx].colInxs = {}; self.mItemRangeRecorder[reInx].colInxs[1] = nowIndex; elseif self.mItemRangeRecorder[#self.mItemRangeRecorder] then local recorder = self.mItemRangeRecorder[#self.mItemRangeRecorder]; recorder.colInxs[#recorder.colInxs + 1] = nowIndex; end else local isExsitRecorder = false; for i = 1, #self.mItemRangeRecorder do local recorder = self.mItemRangeRecorder[i]; if self.mUseSortList[nowIndex].showScMin == recorder.showScMin and self.mUseSortList[nowIndex].showScMax == recorder.showScMax then recorder.colInxs[#recorder.colInxs + 1] = nowIndex; isExsitRecorder = true; break; end end if not isExsitRecorder then local reInx = #self.mItemRangeRecorder + 1; self.mItemRangeRecorder[reInx] = {}; self.mItemRangeRecorder[reInx].showScMin = self.mUseSortList[nowIndex].showScMin self.mItemRangeRecorder[reInx].showScMax = self.mUseSortList[nowIndex].showScMax self.mItemRangeRecorder[reInx].colInxs = {}; self.mItemRangeRecorder[reInx].arrayInx = reInx; self.mItemRangeRecorder[reInx].colInxs[1] = nowIndex; end end end end -- 重新设置排序函数并且刷新页面 function CCListViewDynamic:refreshViewBySortFunc(pSortFunc) if pSortFunc then local function sortIt(a, b) return pSortFunc(a.info, b.info); end self.mSortFunction = sortIt; else self.mSortFunction = nil; end self:refreshView(); end -- 重新设置过滤函数并且刷新页面 function CCListViewDynamic:refreshViewByInfoAttr(pCheckFunc) self.mFiltFunc = pCheckFunc; self:refreshView(); end