/** * reloads data from data source. the view will be refreshed. */ public void ReloadData() { m_eOldDirection = CCScrollViewDirection.None; foreach (CCTableViewCell cell in m_pCellsUsed) { if (m_pTableViewDelegate != null) { m_pTableViewDelegate.TableCellWillRecycle(this, cell); } m_pCellsFreed.Add(cell); cell.Reset(); if (cell.Parent == Container) { Container.RemoveChild(cell, true); } } m_pIndices.Clear(); m_pCellsUsed = new CCArrayForObjectSorting(); _updateCellPositions(); _updateContentSize(); if (m_pDataSource.NumberOfCellsInTableView(this) > 0) { ScrollViewDidScroll(this); } }
public virtual void ScrollViewDidScroll(CCScrollView view) { var uCountOfItems = m_pDataSource.NumberOfCellsInTableView(this); if (uCountOfItems == 0) { return; } int startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0; CCPoint offset = GetContentOffset() * -1; maxIdx = Math.Max(uCountOfItems - 1, 0); CCSize cellSize = m_pDataSource.CellSizeForTable(this); if (m_eVordering == CCTableViewVerticalFillOrder.FillTopDown) { offset.Y = offset.Y + m_tViewSize.Height / Container.ScaleY - cellSize.Height; } startIdx = _indexFromOffset(offset); if (m_eVordering == CCTableViewVerticalFillOrder.FillTopDown) { offset.Y -= m_tViewSize.Height / Container.ScaleY; } else { offset.Y += m_tViewSize.Height / Container.ScaleY; } offset.X += m_tViewSize.Width / Container.ScaleX; endIdx = _indexFromOffset(offset); #if DEBUG_ // For Testing. int i = 0; foreach (object pObj in m_pCellsUsed) { var pCell = (CCTableViewCell)pObj; CCLog.Log("cells Used index {0}, value = {1}", i, pCell.getIdx()); i++; } CCLog.Log("---------------------------------------"); i = 0; foreach (object pObj in m_pCellsFreed) { var pCell = (CCTableViewCell)pObj; CCLog.Log("cells freed index {0}, value = {1}", i, pCell.getIdx()); i++; } CCLog.Log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); #endif if (m_pCellsUsed.Count > 0) { var cell = (CCTableViewCell)m_pCellsUsed[0]; idx = cell.Index; while (idx < startIdx) { _moveCellOutOfSight(cell); if (m_pCellsUsed.Count > 0) { cell = (CCTableViewCell)m_pCellsUsed[0]; idx = cell.Index; } else { break; } } } if (m_pCellsUsed.Count > 0) { var cell = (CCTableViewCell)m_pCellsUsed[m_pCellsUsed.Count - 1]; idx = cell.Index; while (idx <= maxIdx && idx > endIdx) { _moveCellOutOfSight(cell); if (m_pCellsUsed.Count > 0) { cell = (CCTableViewCell)m_pCellsUsed[m_pCellsUsed.Count - 1]; idx = cell.Index; } else { break; } } } for (int j = startIdx; j <= endIdx; j++) { if (m_pIndices.Contains(j)) { continue; } UpdateCellAtIndex(j); } }