0

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.

Eman
  • 1,093
  • 2
  • 26
  • 49
  • I was also lost when checking your project. I think the problem is probably caused by the custom layout. Maybe you can try a default UICollectionViewFlowLayout to see if it works. I will go back to check it later and update you if I find anything. And here are some links may help: [cellforitematindexpath-not-called](https://stackoverflow.com/questions/30804937/cellforitematindexpath-not-called-but-numberofitemsinsection-does/40448382) and [cellforitematindexpath-is-not-being-called](https://stackoverflow.com/questions/14668781/uicollectionviews-cellforitematindexpath-is-not-being-called) – nevermore Sep 20 '19 at 07:49
  • @JackHua-MSFT I disabled the custom layout and it's still not showing up, I'm going to try not using the xib files and see if I get better results, the article I was looking at didn't use them so maybe I'm not able to. – Eman Sep 23 '19 at 17:44

1 Answers1

1

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.

nevermore
  • 15,432
  • 1
  • 12
  • 30
  • I got that too, I didn't think it was good practice to set constraints in a stackview, but guess there's exceptions. I see my images now, I'll have to tweak the custom layout, maybe I missed something. In any case thank you so much Jack. – Eman Sep 24 '19 at 14:26