Custom UICollectionView pinterest layout question

I made an iOS Application which shows 10 photos for a search result at a time, using unsplash.com’s API and lay it out in a pinterest like view - https://www.raywenderlich.com/4829472-uicollectionview-custom-layout-tutorial-pinterest . When the last cell of the collection view is about to be shown, I update the array containing links to images, by appending 10 more images to be shown in an infinite scroll manner. This part of the code works good.

However when I search for say ‘office’, scroll down a few times, the prepare method in custom pinterestflow is used to set X, Y, height and width of all cells.
Without exiting, if I search say ‘flower’, I clear the array containing URLs, and load it up with flower image urls instead. Now the collectionview starts hanging, and a lot of warnings pop up in the debugger - NSConstraint invalid or something.

I am hoping this is some simple error, hence not attaching the code. Would be great if someone lets me know what could be wrong, or if they need access to the entire warning or the code itself.

Here is a sample of debug message I got:
2019-12-02 14:19:14.934997+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d2d250> index path: (<NSIndexPath: 0x9a99c4a2aac0bf55> {length = 2, path = 0 - 0}); frame = (0 0; 117 154.5); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.935585+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d35290> index path: (<NSIndexPath: 0x9a99c4a2aae0bf55> {length = 2, path = 0 - 1}); frame = (117 0; 117 68.6667); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.935666+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d353c0> index path: (<NSIndexPath: 0x9a99c4a2aa80bf55> {length = 2, path = 0 - 2}); frame = (234 0; 117 68.6667); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.935741+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d35810> index path: (<NSIndexPath: 0x9a99c4a2aaa0bf55> {length = 2, path = 0 - 3}); frame = (0 166.5; 117 218.118); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.935815+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d35940> index path: (<NSIndexPath: 0x9a99c4a2aa40bf55> {length = 2, path = 0 - 4}); frame = (117 80.6667; 117 68.6667); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.935885+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d35d90> index path: (<NSIndexPath: 0x9a99c4a2aa60bf55> {length = 2, path = 0 - 5}); frame = (234 80.6667; 117 67.9745); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.935954+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d35ec0> index path: (<NSIndexPath: 0x9a99c4a2aa00bf55> {length = 2, path = 0 - 6}); frame = (0 396.618; 117 154.514); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.936026+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d36310> index path: (<NSIndexPath: 0x9a99c4a2aa20bf55> {length = 2, path = 0 - 7}); frame = (117 161.333; 117 77.25); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.936100+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d36440> index path: (<NSIndexPath: 0x9a99c4a2abc0bf55> {length = 2, path = 0 - 8}); frame = (234 160.641; 117 154.5); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.936170+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d36e10> index path: (<NSIndexPath: 0x9a99c4a2abe0bf55> {length = 2, path = 0 - 9}); frame = (0 563.132; 117 154.494); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.936240+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d48160> index path: (<NSIndexPath: 0x9a99c4a2aac0bf55> {length = 2, path = 0 - 0}); frame = (0 0; 117 154.5); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.936332+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d38090> index path: (<NSIndexPath: 0x9a99c4a2aae0bf55> {length = 2, path = 0 - 1}); frame = (117 0; 117 68.6667); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

2019-12-02 14:19:14.936404+0530 Piclex[359:9695] [CollectionView] Layout attributes <UICollectionViewLayoutAttributes: 0x102d1e960> index path: (<NSIndexPath: 0x9a99c4a2aa80bf55> {length = 2, path = 0 - 2}); frame = (234 0; 117 68.6667); were received from the layout <Piclex.FlowLayout: 0x102a02340> but are not valid for the data source counts. Attributes will be ignored.

@haawa Can you please help with this when you get a chance? Thank you - much appreciated! :]

@haawa - Do let me know if you need a copy of the source code, if that helps in troubleshooting the error.

In short, when I have a number of cells in custom collection view, and when I change source of array where custom collection view displays data from, the phone starts lagging and above debug messages are shown.

Hey there, I have a similar bug, were you able to solve it?

Nope buddy.
Filling in additional chars so that this short reply can be posted, please ignore this line.

I had the same issue it had to do with the cache that is set in the custom layout… in the prepare function i added cache.removeAll() as the very first line and that fixed the issues

2 Likes

Wow that worked! Thanks a lot

@alouanemed Do you still have issues with this?

This topic was automatically closed after 166 days. New replies are no longer allowed.