Big UICollectionViewCell disappears with custom layout

I have subclassed UICollectionViewLayout . So far so good. However, I have a few cells that are wider than the screen, and sometimes they disappear when scrolling. When you scroll a little more, they will magically appear where they should be. I can show you my code, but I think that nothing bad happens with it, since it works in 90% of cases. However, sometimes really large cells disappear (more than twice the size of the screen).

 NSMutableArray* attributes = [NSMutableArray array]; for (int section=0; section < [[self collectionView] numberOfSections]; section++) { [attributes addObject:[self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]]]; for (int row=0; row < [[self collectionView] numberOfItemsInSection:section]; row++) { NSIndexPath* indexPath = [NSIndexPath indexPathForItem:row inSection:section]; [attributes addObject:[self layoutAttributesForItemAtIndexPath:indexPath]]; } } return attributes; 

I also have these messages: the UICollectionView cell disappears and the Large cells in the UICollectionView are deleted while the cell is still displayed. However, the solution is not mentioned. Can someone help me with this? Maybe the problem is on the side of Apple? And if so, is there anything I can do to solve this myself?

+6
source share
2 answers

Sorry to say: I'm sure this is a real mistake in the UICollectionView; I came across this same thing a few weeks ago. I made a small program to demonstrate the error and filed a RADAR with Apple, but have not yet heard about whether they plan to fix it. The best workaround I can think of (warning: I haven't implemented this workaround yet) is to notice that the layout attributes are very far from the edges of the screen, intentionally change the borders of the cell attributes, so it only slightly leaves the screen and it is possible to save this offset (the amount that you cut off from what the real borders should be), as an additional custom field in the layoutAttributes attributes, so your cell knows to display the content correctly. Which seems like a gross hack, but it should work.

+5
source

Are you sure you returned the correct attribute object for this cell when the -(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect method -(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect called, and when rect is only part of your cell?

0
source

All Articles