protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item) { var reuse = tableView.DequeueReusableCell(CellIdentifier); if (reuse != null) return reuse; var toReturn = new TableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier); return toReturn; }
//管理子项对象集合 private void UpdateCells(int startIndex = 0, int endIndex = 0) { //Debug.Log("===UpdateCells===startIndex" + startIndex + "====endIndex:" + endIndex); //Debug.Log("===UpdateCells===m_cellsUsed.Count" + m_cellsUsed.Count); while (m_cellsUsed.Count > 0) { TableViewCell cell = m_cellsUsed[0]; if (cell.Idx < startIndex) { this._moveCellOutOfSight(cell); } else { break; } } while (m_cellsUsed.Count > 0) { TableViewCell cell = m_cellsUsed[m_cellsUsed.Count - 1]; if (cell.Idx > endIndex) { this._moveCellOutOfSight(cell); } else { break; } } ////根据开始跟结束下标,重新生成子项对象 for (int i = startIndex; i <= endIndex; i++) { if (m_indices.Contains(i)) { continue; } updateCellAtIndex(i); } }
private void ReuseCells(int scrollDirection) { if (cells.Count < 1) { return; } if (scrollDirection > 0) { TableViewCell <T> firstCell = cells.First.Value; while (firstCell.Bottom.y > visibleRect.y)//直到超出visibleRect可视范围 { TableViewCell <T> lastCell = cells.Last.Value; UpdateCellForIndex(firstCell, lastCell.DataIndex + 1);//将最后一个cell信息取出,用于显示 firstCell.Top = lastCell.Bottom + new Vector2(0.0f, -spacingHeight); cells.AddLast(firstCell); //头变尾 cells.RemoveFirst(); //第一个cell从链表中擦除 firstCell = cells.First.Value; //将下一个cell设置为要更新的cell } FillVisibleRectWithCells(); } else if (scrollDirection < 0) { TableViewCell <T> lastCell = cells.Last.Value; while (lastCell.Top.y < visibleRect.y - visibleRect.height) { TableViewCell <T> firstCell = cells.First.Value; UpdateCellForIndex(lastCell, firstCell.DataIndex - 1); lastCell.Bottom = firstCell.Top + new Vector2(0.0f, spacingHeight); cells.AddFirst(lastCell); cells.RemoveLast(); lastCell = cells.Last.Value; } } }
public void TestAddTwoRows() { TableViewMock table = new TableViewMock(320, 15); TableViewCell a1 = new TableViewCellMock1(table.Width, 10); TableViewCell a2 = new TableViewCellMock2(table.Width, 15); TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new TableViewCell[] { a1 }); table.DataSource = adapter; table.Delegate = adapter; table.ReloadData(); adapter.Add(a2); table.ReloadNewData(); TableViewCell b1 = table.FirstVisibleCell; TableViewCell b2 = b1.NextCell; Assert.AreSame(a1, b1); Assert.AreSame(a2, b2); AssertVisibleRows(table, 0, 1); }
internal void AssertVisibleRows(TableView table, params string[] values) { Assert.AreEqual(values.Length, table.VisibleCellsCount, "expected: " + StringArrayToString(values) + "\n" + "actual: " + VisibleCellsToString(table)); int index = 0; TableViewCell cell = table.FirstVisibleCell; TableViewCell lastCell = null; while (cell != null) { ConsoleTextEntryView textCell = cell as ConsoleTextEntryView; Assert.IsNotNull(textCell); Assert.AreEqual(values[index++], textCell.Value); lastCell = cell; cell = cell.NextCell; } Assert.AreEqual(values.Length, index); Assert.AreSame(lastCell, table.LastVisibleCell); }
public TableViewCell tableCellAtIndex(UIGridView table, TableViewCell cell, int idx) { UILevelTableViewCell itemCell = cell as UILevelTableViewCell; UILevelItem m_UILevelItem = null; if (itemCell == null) { itemCell = new UILevelTableViewCell(); m_UILevelItem = UILevelItem.Create(); itemCell._UILevelItem = m_UILevelItem; FlushItem(m_UILevelItem, idx); EventTriggerClick.Get(m_UILevelItem.gameObject).onClick = (o) => { SelectItem(table, m_UILevelItem, itemCell.Idx); }; } else { m_UILevelItem = itemCell._UILevelItem; FlushItem(m_UILevelItem, idx); } return(itemCell); }
/** * reloads data from data source. the view will be refreshed. */ public void reloadData() { updateLayout(); if (m_cellsUsed.Count > 0) { for (int i = 0; i < m_cellsUsed.Count; i++) { TableViewCell cell = m_cellsUsed[i]; m_cellsFreed.Add(cell); cell.reset(); cell.node.SetActive(false); } } m_cellsUsed.Clear(); m_indices.Clear(); this._updateCellPositions(); if (DataSource.numberOfCellsInTableView(this) > 0) { this.OnScrollValueChanged(m_nearestScrollVec); } }
private void AddCell(TableViewCell cell, float offset, bool atFirst) { if (direction == Direction.Verical) { offset = -offset; } var rect = cell.Rect; if (rect.parent != scrollRect.content) { rect.SetParent(scrollRect.content, false); } rect.localScale = Vector3.one; if (direction == Direction.Verical) { rect.pivot = new Vector2(0.5f, 1); rect.anchorMin = rect.anchorMax = new Vector2(0.5f, 1); rect.anchoredPosition = new Vector2(0, offset); //rect.localPosition = new Vector3(0, offset, 0); } else { rect.pivot = new Vector2(0f, 0.5f); rect.anchorMin = rect.anchorMax = new Vector2(0f, 0.5f); rect.anchoredPosition = new Vector2(offset, 0); //rect.localPosition = new Vector3(offset, 0, 0); } if (atFirst) { visibleCells.AddFirst(cell); } else { visibleCells.AddLast(cell); } }
public TableViewCell CellForRowInTableView(TableView tableView, int row) { TableViewCell cell = tableView.ReusableCellForRow("ChallengeTableViewCell", row); cell.name = "Cell " + row; ChallengeTableViewCell challengeTableViewCell = cell.GetComponent <ChallengeTableViewCell>(); switch (GlobalVariables.tableViewDataType) { case 0: challengeTableViewCell.SetDefaultImage(); ChallengeDTO challenge = GlobalVariables.challengeResponse.challenges[row]; StartCoroutine(challengeTableViewCell.LoadImage(challenge.imageUrl)); break; case 1: break; default: break; } return(cell); }
/// <summary> /// 创建visibleRect范围内可显示的cell /// </summary> private void FillVisibleRectWithCells() { if (cells.Count < 1) { return; } TableViewCell <T> lastCell = cells.Last.Value; //取出cells链表的第一个(后进先出) int nextCellDataIndex = lastCell.DataIndex + 1; //下一个cell的索引 //下一个cell 的位置 上一个lastCell的下边界Bottom加上各个cell 的间隔 spacingHeight Vector2 nextCellTop = lastCell.Bottom + new Vector2(0.0f, -spacingHeight); while (nextCellDataIndex < tableData.Count && nextCellTop.y >= visibleRect.y - visibleRect.height) //直到list列表中的最后一个,且每个cell 的位置必须是在visibleRect可视的 { TableViewCell <T> cell = CreateCellForIndext(nextCellDataIndex); //根据下一个索引创建cell cell.Top = nextCellTop; //赋予位置信息 //做循环条件 lastCell = cell; nextCellDataIndex = lastCell.DataIndex + 1; nextCellTop = lastCell.Bottom + new Vector2(0.0f, -spacingHeight); } }
protected override bool OnMouseDown(Event evt, TableViewCell cell) { ClickedCell = cell; return(true); }
public TestCellPredefinedAdapter(TableViewCell[] cells) { m_cells = new List<TableViewCell>(cells); }
IEnumerator ScrollFunc() { while (isPointerEntered) { while (isPointerEntered && Input.GetMouseButtonDown(0) == false) { yield return(null); } TableViewCell cell = null; var delta = Vector2.zero; var downPosition = Input.mousePosition; var originalTableViewY = positionY; var results = new List <RaycastResult>(); raycaster.Raycast(new PointerEventData(EventSystem.current) { position = Input.mousePosition }, results); if (results.Count == 0) { continue; } var tr = results[0].gameObject.transform; while (tr.parent != null) { cell = tr.GetComponent <TableViewCell>(); if (cell != null) { break; } tr = tr.parent; } if (cell == null) { continue; } while (isPointerEntered && Input.GetMouseButton(0)) { delta = Input.mousePosition - downPosition; if (delta.y < -10) { cell.rt.pivot = new Vector2(cell.rt.pivot.x, 1); } else if (delta.y > 10) { cell.rt.pivot = new Vector2(cell.rt.pivot.x, 0); } if (delta.y > 150) { if (ScrollDown()) { //yield return new WaitForSeconds(1.0f / 60 * 11); cell.ScaleTo(5, Vector3.one, Easing.SineOut); break; } else { break; } } else if (delta.y < -150) { if (ScrollUp()) { //yield return new WaitForSeconds(1.0f / 60 * 11); cell.ScaleTo(5, Vector3.one, Easing.SineOut); break; } else { break; } } if (delta.y > 0 && cell.index != 0) { GetCell(cell.index - 1).transform.localScale = new Vector3(1, 1 - Mathf.Clamp(Mathf.Abs(delta.y / 1000), 0, 0.3f), 1); } cell.transform.localScale = new Vector3(1, 1 + Mathf.Clamp(Mathf.Abs(delta.y / 1000), 0, 0.3f), 1); yield return(null); } if (Mathf.Abs(delta.magnitude) <= 10) { cell.gameObject.SendMessage("OnClickCell", SendMessageOptions.DontRequireReceiver); } else { if (cell.index != 0) { GetCell(cell.index - 1).ScaleTo(5, Vector3.one, Easing.SineOut); } if (cell.rt.pivot.y == 1) { yield return(cell.ScaleTo(25, Vector3.one, Easing.SineOut)); } else { yield return(cell.ScaleTo(5, Vector3.one, Easing.SineOut)); } while (isPointerEntered && Input.GetMouseButton(0)) { yield return(null); } } } }
public void Add(TableViewCell cell) { m_cells.Add(cell); }
public override UITableViewCell GetCell(UITableView tableView, Foundation.NSIndexPath indexPath) { TableViewCell cell = tableView.DequeueReusableCell(TableViewCell.Key) as TableViewCell ?? TableViewCell.Create(); cell.BindData(arrMenuText[indexPath.Row], arrMenuIcon[indexPath.Row]); return(cell); }
// セルを再利用して表示を更新するメソッド private void ReuseCells(int scrollDirection) { if (cells.Count < 1) { return; } if (CachedScrollRect.horizontal) { if (scrollDirection > 0) { TableViewCell <T> firstCell = cells.First.Value; while (firstCell.Right.x < visibleRect.x) { TableViewCell <T> lastCell = cells.Last.Value; UpdateCellForIndex(firstCell, lastCell.DataIndex + 1); firstCell.Left = lastCell.Right + new Vector2(spacingWidth, 0.0f); cells.AddLast(firstCell); cells.RemoveFirst(); firstCell = cells.First.Value; } FillVisibleRectWithCells(); } else if (scrollDirection < 0) { TableViewCell <T> lastCell = cells.Last.Value; while (lastCell.Left.x > visibleRect.x + visibleRect.width) { TableViewCell <T> firstCell = cells.First.Value; UpdateCellForIndex(lastCell, firstCell.DataIndex - 1); lastCell.Right = firstCell.Left + new Vector2(-spacingWidth, 0.0f); cells.AddFirst(lastCell); cells.RemoveLast(); lastCell = cells.Last.Value; } } } else { if (scrollDirection > 0) { // 上にスクロールしている場合、visibleRectの範囲より上にあるセルを // 順に下に移動して内容を更新する TableViewCell <T> firstCell = cells.First.Value; while (firstCell.Bottom.y > visibleRect.y) { TableViewCell <T> lastCell = cells.Last.Value; UpdateCellForIndex(firstCell, lastCell.DataIndex + 1); firstCell.Top = lastCell.Bottom + new Vector2(0.0f, -spacingHeight); cells.AddLast(firstCell); cells.RemoveFirst(); firstCell = cells.First.Value; } // visibleRectの範囲内に空きがあればセルを作成する FillVisibleRectWithCells(); } else if (scrollDirection < 0) { // 下にスクロールしている場合、visibleRectの範囲より下にあるセルを // 順に上に移動して内容を更新する TableViewCell <T> lastCell = cells.Last.Value; while (lastCell.Top.y < visibleRect.y - visibleRect.height) { TableViewCell <T> firstCell = cells.First.Value; UpdateCellForIndex(lastCell, firstCell.DataIndex - 1); lastCell.Bottom = firstCell.Top + new Vector2(0.0f, spacingHeight); cells.AddFirst(lastCell); cells.RemoveLast(); lastCell = cells.Last.Value; } } } }
public void TestReusableCells() { MockCellEntry[] cells = { new MockCellEntry(typeof(TableViewCellMock1), 10), new MockCellEntry(typeof(TableViewCellMock2), 10), new MockCellEntry(typeof(TableViewCellMock3), 10), new MockCellEntry(typeof(TableViewCellMock1), 10), new MockCellEntry(typeof(TableViewCellMock2), 10), new MockCellEntry(typeof(TableViewCellMock3), 10), }; TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells); TableViewMock table = new TableViewMock(320, 25); table.DataSource = adapter; table.Delegate = adapter; table.ReloadData(); TableViewCell a1 = table.FirstVisibleCell; TableViewCell a2 = a1.NextCell; TableViewCell a3 = a2.NextCell; Assert.AreEqual(typeof(TableViewCellMock1), a1.GetType()); Assert.AreEqual(typeof(TableViewCellMock2), a2.GetType()); Assert.AreEqual(typeof(TableViewCellMock3), a3.GetType()); table.Scroll(10); TableViewCell b1 = table.FirstVisibleCell; TableViewCell b2 = b1.NextCell; TableViewCell b3 = b2.NextCell; Assert.AreSame(a2, b1); Assert.AreSame(a3, b2); Assert.AreSame(a1, b3); table.Scroll(10); b1 = table.FirstVisibleCell; b2 = b1.NextCell; b3 = b2.NextCell; Assert.AreSame(a3, b1); Assert.AreSame(a1, b2); Assert.AreSame(a2, b3); table.Scroll(10); b1 = table.FirstVisibleCell; b2 = b1.NextCell; b3 = b2.NextCell; Assert.AreSame(a1, b1); Assert.AreSame(a2, b2); Assert.AreSame(a3, b3); table.Scroll(5); b1 = table.FirstVisibleCell; b2 = b1.NextCell; b3 = b2.NextCell; Assert.AreSame(a1, b1); Assert.AreSame(a2, b2); Assert.AreSame(a3, b3); table.Scroll(-5); b1 = table.FirstVisibleCell; b2 = b1.NextCell; b3 = b2.NextCell; Assert.AreSame(a1, b1); Assert.AreSame(a2, b2); Assert.AreSame(a3, b3); table.Scroll(-10); b1 = table.FirstVisibleCell; b2 = b1.NextCell; b3 = b2.NextCell; Assert.AreSame(a3, b1); Assert.AreSame(a1, b2); Assert.AreSame(a2, b3); table.Scroll(-10); b1 = table.FirstVisibleCell; b2 = b1.NextCell; b3 = b2.NextCell; Assert.AreSame(a2, b1); Assert.AreSame(a3, b2); Assert.AreSame(a1, b3); table.Scroll(-10); b1 = table.FirstVisibleCell; b2 = b1.NextCell; b3 = b2.NextCell; Assert.AreSame(a1, b1); Assert.AreSame(a2, b2); Assert.AreSame(a3, b3); Assert.AreEqual(1, TableViewCellMock1.instanceCount); Assert.AreEqual(1, TableViewCellMock2.instanceCount); Assert.AreEqual(1, TableViewCellMock3.instanceCount); }
protected void UpdateContents() { UpdateContentSize(); // スクロールさせる内容のサイズを更新する /* * mark 移动content到目标位置 */ UpdateVisibleRect(); // visibleRectを更新する if (cells.Count < 1) { /* * 查找添加第一个在可视返回内的item */ if (CachedScrollRect.horizontal) { Vector2 cellLeft = new Vector2(padding.left, 0.0f); for (int i = 0; i < tableData.Count; ++i) { float cellWidth = CellWidthAtIndex(i); Vector2 cellRight = cellLeft + new Vector2(cellWidth, 0.0f); if ((cellLeft.x >= visibleRect.x && cellLeft.x <= visibleRect.x + visibleRect.width) ||// mark visible rect (cellRight.x >= visibleRect.x && cellRight.x <= visibleRect.x + visibleRect.width)) { TableViewCell <T> cell = CreateCellForIndex(i); cell.Left = cellLeft; break; } cellLeft = cellRight + new Vector2(spacingWidth, 0.0f); } } else { Vector2 cellTop = new Vector2(0.0f, -padding.top); for (int i = 0; i < tableData.Count; ++i) { float cellHeight = CellHeightAtIndex(i); Vector2 cellBottom = cellTop + new Vector2(0.0f, -cellHeight); if ((cellTop.y <= visibleRect.y && cellTop.y >= visibleRect.y - visibleRect.height) || (cellBottom.y <= visibleRect.y && cellBottom.y >= visibleRect.y - visibleRect.height)) { TableViewCell <T> cell = CreateCellForIndex(i); cell.Top = cellTop; break; } cellTop = cellBottom + new Vector2(0.0f, spacingHeight); } } // visibleRectの範囲内に空きがあればセルを作成する FillVisibleRectWithCells(); } else { LinkedListNode <TableViewCell <T> > node = cells.First; //mark cell index UpdateCellForIndex(node.Value, node.Value.DataIndex); node = node.Next; while (node != null) { UpdateCellForIndex(node.Value, node.Previous.Value.DataIndex + 1); if (CachedScrollRect.horizontal) { node.Value.Left = node.Previous.Value.Right + new Vector2(spacingWidth, 0.0f); } else { node.Value.Top = node.Previous.Value.Bottom + new Vector2(0.0f, -spacingHeight); } node = node.Next; } // visibleRectの範囲内に空きがあればセルを作成する FillVisibleRectWithCells(); } OnScrollPosChanged(CachedScrollRect.content.position); }
private bool IsAdCell(TableViewCell cell) { return(cell is NativeAdTableViewCell); }
private static Utils.Tuple <string, bool> TableViewEditorValidator(TableViewCell tableViewCell, object value) { // do not accept "d" return(((string)value).Contains("d") ? new Utils.Tuple <string, bool>("", false) : new Utils.Tuple <string, bool>("", true)); }
protected override bool OnMouseDown(Event evt, TableViewCell cell) { ConsoleViewCell consoleCell = cell as ConsoleViewCell; if (consoleCell != null && consoleCell.OnMouseDown(evt)) { return true; } return base.OnMouseDown(evt, cell); }
protected override bool OnMouseDown(Event evt, TableViewCell cell) { ClickedCell = cell; return true; }
protected void UpdateContentsByIndex(int index) { UpdateContentSize(); Vector2 sizeOfContent = ((RectTransform)CachedScrollRect.content.transform).sizeDelta; Vector2 sizeOfScroll = CachedRectTransform.sizeDelta; float min = -(sizeOfContent.x - sizeOfScroll.x); float max = 0; float contentX = (index) * -CellWidthAtIndex(index) + (index - 1) * -spacingWidth; if (contentX > max) { contentX = max; } if (contentX < min) { contentX = min; } Vector3 posContent = cachedScrollRect.content.transform.localPosition; posContent.x = contentX; cachedScrollRect.content.transform.localPosition = posContent; UpdateVisibleRect(); // visibleRectを更新する if (cells.Count < 1) { /* * 查找添加第一个在可视返回内的item */ if (CachedScrollRect.horizontal) { Vector2 cellLeft = new Vector2(padding.left, 0.0f); for (int i = 0; i < tableData.Count; ++i) { float cellWidth = CellWidthAtIndex(i); Vector2 cellRight = cellLeft + new Vector2(cellWidth, 0.0f); if ((cellLeft.x >= visibleRect.x && cellLeft.x <= visibleRect.x + visibleRect.width) ||// mark visible rect (cellRight.x >= visibleRect.x && cellRight.x <= visibleRect.x + visibleRect.width)) { TableViewCell <T> cell = CreateCellForIndex(i); cell.Left = cellLeft; break; } cellLeft = cellRight + new Vector2(spacingWidth, 0.0f); } } else { Vector2 cellTop = new Vector2(0.0f, -padding.top); for (int i = 0; i < tableData.Count; ++i) { float cellHeight = CellHeightAtIndex(i); Vector2 cellBottom = cellTop + new Vector2(0.0f, -cellHeight); if ((cellTop.y <= visibleRect.y && cellTop.y >= visibleRect.y - visibleRect.height) || (cellBottom.y <= visibleRect.y && cellBottom.y >= visibleRect.y - visibleRect.height)) { TableViewCell <T> cell = CreateCellForIndex(i); cell.Top = cellTop; break; } cellTop = cellBottom + new Vector2(0.0f, spacingHeight); } } // visibleRectの範囲内に空きがあればセルを作成する FillVisibleRectWithCells(); } else { cells.First.Value.DataIndex = index - 1; float cellWidth = CellWidthAtIndex(index); Vector2 cellLeft = new Vector2(padding.left + (index - 1) * cellWidth + (index - 2) * spacingWidth, 0.0f); cells.First.Value.Left = cellLeft; LinkedListNode <TableViewCell <T> > node = cells.First;//mark cell index UpdateCellForIndex(node.Value, node.Value.DataIndex); node = node.Next; while (node != null) { UpdateCellForIndex(node.Value, node.Previous.Value.DataIndex + 1); if (CachedScrollRect.horizontal) { node.Value.Left = node.Previous.Value.Right + new Vector2(spacingWidth, 0.0f); } else { node.Value.Top = node.Previous.Value.Bottom + new Vector2(0.0f, -spacingHeight); } node = node.Next; } // visibleRectの範囲内に空きがあればセルを作成する FillVisibleRectWithCells(); } OnScrollPosChanged(CachedScrollRect.content.position); }