Beispiel #1
0
    //Will be called by the TableView when a cell needs to be created for display
    public TableViewCell GetCellForRowInTableView(TableView tableView, int row)
    {
        UICellBase cell = tableView.GetReusableCell(cellPrefab.reuseIdentifier) as UICellBase;

        if (cell == null)
        {
            cell      = (UICellBase)GameObject.Instantiate(cellPrefab);
            cell.name = "UICellBase" + (++numInstancesCreated).ToString();
            Rect    rccell      = (cellPrefab.transform as RectTransform).rect;
            Rect    rctable     = (tableView.transform as RectTransform).rect;
            Vector2 sizeCell    = (cellPrefab.transform as RectTransform).sizeDelta;
            Vector2 sizeTable   = (tableView.transform as RectTransform).sizeDelta;
            Vector2 sizeCellNew = sizeCell;
            sizeCellNew.x = rctable.width;

            AddCellItem(cell, tableView, row);
        }
        cell.totalItem = totalItem;
        if (oneCellNum != cell.oneCellNum)
        {
            //relayout
            cell.ClearAllItem();
            AddCellItem(cell, tableView, row);
        }
        cell.oneCellNum = oneCellNum;
        cell.rowIndex   = row;
        cell.UpdateItem(listItem);
        return(cell);
    }
    //Will be called by the TableView when a cell needs to be created for display
    public TableViewCell GetCellForRowInTableView(TableView tableView, int row)
    {
        UICellBase cell = tableView.GetReusableCell(cellPrefab.reuseIdentifier) as UICellBase;

        if (cell == null)
        {
            cell      = (UICellBase)GameObject.Instantiate(cellPrefab);
            cell.name = "UICellBase" + (++numInstancesCreated).ToString();
            Rect    rccell      = (cellPrefab.transform as RectTransform).rect;
            Rect    rctable     = (tableView.transform as RectTransform).rect;
            Vector2 sizeCell    = (cellPrefab.transform as RectTransform).sizeDelta;
            Vector2 sizeTable   = (tableView.transform as RectTransform).sizeDelta;
            Vector2 sizeCellNew = sizeCell;
            sizeCellNew.x = rctable.width;

            for (int i = 0; i < oneCellNum; i++)
            {
                int            itemIndex  = row * oneCellNum + i;
                float          cell_space = 10;
                UICellItemBase item       = (UICellItemBase)GameObject.Instantiate(cellItemPrefab);
                //item.itemDelegate = this;
                Rect rcItem = (item.transform as RectTransform).rect;
                item.width  = (rctable.width - cell_space * (oneCellNum - 1)) / oneCellNum;
                item.height = heightCell;
                item.transform.SetParent(cell.transform, false);
                item.index         = itemIndex;
                item.totalItem     = totalItem;
                item.callbackClick = OnCellItemDidClick;

                cell.AddItem(item);
            }
        }
        cell.totalItem  = totalItem;
        cell.oneCellNum = oneCellNum;
        cell.rowIndex   = row;
        foreach (UICellItemBase it_base in cell.listItem)
        {
            UILearnProgressCellItem ui = it_base as UILearnProgressCellItem;
            ui.SetItemType(itemType);
            ui.colorSel   = colorSel;
            ui.colorUnSel = colorUnSel;
        }
        cell.UpdateItem(listItem);
        return(cell);
    }
Beispiel #3
0
    //Will be called by the TableView when a cell needs to be created for display

    public TableViewCell GetCellForRowInTableView(TableView tableView, int row)
    {
        UICellBase cell = tableView.GetReusableCell(cellPrefab.reuseIdentifier) as UICellBase;

        if (cell == null)
        {
            cell      = (UICellBase)GameObject.Instantiate(cellPrefab);
            cell.name = "UICellBase" + (++numInstancesCreated).ToString();
            Rect    rccell      = (cellPrefab.transform as RectTransform).rect;
            Rect    rctable     = (tableView.transform as RectTransform).rect;
            Vector2 sizeCell    = (cellPrefab.transform as RectTransform).sizeDelta;
            Vector2 sizeTable   = (tableView.transform as RectTransform).sizeDelta;
            Vector2 sizeCellNew = sizeCell;
            sizeCellNew.x = rctable.width;

            //  cell.SetCellSize(sizeCellNew);

            // Debug.LogFormat("TableView Cell Add Item:rcell:{0}, sizeCell:{1},rctable:{2},sizeTable:{3}", rccell, sizeCell, rctable, sizeTable);
            // oneCellNum = (int)(rctable.width / heightCell);
            //int i =0;
            for (int i = 0; i < oneCellNum; i++)
            {
                int            itemIndex  = row * oneCellNum + i;
                float          cell_space = 10;
                UICellItemBase item       = (UICellItemBase)GameObject.Instantiate(cellItemPrefab);
                //item.itemDelegate = this;
                Rect rcItem = (item.transform as RectTransform).rect;
                item.width  = (rctable.width - cell_space * (oneCellNum - 1)) / oneCellNum;
                item.height = heightCell;
                item.transform.SetParent(cell.transform, false);
                item.index         = itemIndex;
                item.totalItem     = totalItem;
                item.callbackClick = OnCellItemDidClick;

                cell.AddItem(item);
            }
        }
        cell.totalItem  = totalItem;
        cell.oneCellNum = oneCellNum;
        cell.rowIndex   = row;
        cell.UpdateItem(listItem);
        return(cell);
    }