1

I searched all around the web and found .. NOTHING

So let me tell you my problem! I have this :

  • 1 collection View
  • 1 datasource
  • 2 layout
  • 2 prototyp cells

Then I want to make 2 different styles , in grid and in list to display items.

My problem is when I use ReloadData(), the 1st time, it's OK, but the others times, cells are changing. I don't know why, I don't know how to avoid this changes..

See my code :

In Constructor

collectionViewTransactions.CollectionViewLayout = new CollectionViewLayoutGrid();
collectionViewTransactions.DataSource = new TransactionCollectionViewSource();

In 1 of method button to switch

private void TransactionsChangeToGrid(object sender, EventArgs ea)
    {
        allCategoryTmplViewController.IsGrid = true;

        collectionViewTransactions.CollectionViewLayout = new CollectionViewLayoutGrid();
        collectionViewTransactions.ReloadData();
    }

In my GetCell method in my datasource

public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
    {
        Transaction transaction = Transactions[indexPath.Row];


        if(allCategoryTmplViewController.IsGrid)
        {
            var cell = (TransactionCellGrid)collectionView.DequeueReusableCell("transactionGrid", indexPath);
            cell.UpdateRow(transaction);
            return cell;
        }
        else if (!allCategoryTmplViewController.IsGrid)
        {
            var cell = (TransactionCellList)collectionView.DequeueReusableCell("transactionList", indexPath);
            cell.UpdateRow(transaction);
            return cell;
        }
        return new UICollectionViewCell();
    }

It works the 1st time, but after it doesn't !

Do I have to use invalidateLayout() method ? and if so, where ? and when ?

Thanks for answer

0 Answers0