Search code examples
xamarin.iosuicollectionviewuicollectionviewlayout

Custom Collection View is not showing up


I'm working on an app that'll have a range of images and the collectionview is not showing up at all. I was following this article, which I translated to C#.

here is an example app I made to show a minimal example of what I'm trying to do.

When I run through the code, GetCell in the collection source isn't firing which I know is the problem, but I don't know why it's not firing and I'm simply at a lost on what I'm missing.


Solution

  • I test it again today and I can make sure that the problem is caused by the MosaicCollectionLayout.

    What I did today is that I removed your collectionView and add a new collectionView, then I add Constrains to it with a fixed height and width(to make sure it appears even if there is no data), then I change the layout to FlowLayout, it works, here is the screenshot:

    enter image description here

    After that, I changed the layout back to MosaicCollectionLayout, I get an exception in the line _cachedAttributes.Reverse(lastIndex.Row, firstMatchIndex.Value); inside the method LayoutAttributesForElementsInRect.

    I checked the article and did not find a solution yet. Maybe there is some mistakes in the codes translated from swift to C#. So the problem is not related to the xib, please check the code in the method LayoutAttributesForElementsInRect.You can also try add Constrains to your collectionView. Hope these information helps you.