//目前只支持删除可见区域内的数据 public void removeData(int begin, int end) { int dataCount = dataLocator.source.Count; if (begin < 0 || begin >= dataCount) { Debug.Log("索引不合法"); return; } if (end < 0 || end >= dataCount) { Debug.Log("索引不合法"); return; } //删除数据 for (int i = end; i >= begin; i--) { dataLocator.source.RemoveAt(i); } //删除这个位置后面的数据 bool needClear = false; int fillBeginIndex = 0; for (int i = lineDataList.Count - 1; i >= 0; i--) { LineData ld = lineDataList[i]; fillBeginIndex = ld.beginIndex; recycleLine(ld); lineDataList.RemoveAt(i); if (ld.inLine(begin)) { break; } } List <GridDataSource> source = dataLocator.GetDataSource(); fillData(fillBeginIndex, source); setViewIndex(fillBeginIndex, true); }
/// <summary> /// 定位显示到某一行 /// </summary> /// <param name="index"></param> public void setViewIndex(int index, bool force) { //空列表 if (lineDataList.Count == 0) { return; } //不合法索引 if (index < 0 || index >= dataLocator.source.Count) { Debug.Log("索引不合法"); return; } int lastBegin = allBeginLine; int lastEnd = allEndLine; int findLine = INVALID_POS; for (int i = 0; i < lineDataList.Count; i++) { LineData tempData = lineDataList[i]; if (tempData.inLine(index)) { findLine = i; virtualPos = tempData.childLineY; ContentAnchorY = virtualPos; break; } } //如果定位的行不够填充整个视口,直接拉到最低 float tempContentHeight = ContentHeight; if (tempContentHeight - virtualPos < ViewHeight) { //设置位置,向上查找 if (tempContentHeight >= ViewHeight) { virtualPos = tempContentHeight - ViewHeight; } else { virtualPos = 0; } ContentAnchorY = virtualPos; //向上填充 fillToTop_end(findLine, ref allBeginLine); //向下填充 fillToBottom_end(findLine, ref allEndLine); } else { allBeginLine = findLine; //向下填充 fillToBottom_end(findLine, ref allEndLine); } if (lastBegin != allBeginLine || lastEnd != allEndLine) { if (lastBegin == INVALID_POS || lastEnd == INVALID_POS || force) { drawView(); } else { drawDirtyView(lastBegin, lastEnd, allBeginLine, allEndLine); } } }