mokagio / UICollectionViewLeftAlignedLayout

A layout for UICollectionView that aligns the cells to the left.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cached frame mismatch

ipedro opened this issue · comments

hey there, first of all nice pod :)

It's working for me, but I get this warning. Any clues?

UICollectionViewFlowLayout has cached frame mismatch for index path <NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1} - cached value: {{179, 0}, {136.33333333333334, 30}}; expected value: {{217.66666666666666, 0}, {136.33333333333334, 30}}

This is likely occurring because the flow layout subclass UICollectionViewLeftAlignedLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

I'm getting this as well. I'll let you know if I find the issue

Hi @ipedro and @jmesmith thanks for using UICollectionViewLeftAlignedLayout, and for taking the time to report an issue 😃 And sorry for this my slow response time 😞

I tried to reproduce, but haven't been able to. Could you give me more details? Useful things would be:

  • Xcode version
  • iOS version
  • Snippet of code that generates the warning, or the set of frames used if you are not able to disclose it.

Thanks guys, I'm sure we'll figure this out together 👍

Hi @mokagio, I'm getting the same error as well. I'm using iOS 9 and Xcode 7 Beta 4. I tried the following but it did not solve the problem. Thanks.

UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath];

to

UICollectionViewLayoutAttributes* currentItemAttributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy];

Hi @mokagio,

I have the same problem on iOS 9 beta. I don't have it running on iOS 8.
I'm building with Xcode 6.4 - iOS8 base SDK

Here is the full console log :

2015-08-04 15:01:54.286 App[329:22907] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-08-04 15:01:54.286 App[329:22907] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2015-08-04 15:01:54.287 App[329:22907] The relevant UICollectionViewFlowLayout instance is <UICollectionViewLeftAlignedLayout: 0x157124290>, and it is attached to <UICollectionView: 0x1568aac00; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15713b5c0>; layer = <CALayer: 0x1570fab30>; contentOffset: {0, -64}; contentSize: {0, 0}> collection view layout: <UICollectionViewLeftAlignedLayout: 0x157124290>.
2015-08-04 15:01:54.287 App[329:22907] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-08-04 15:02:17.819 App[329:22907] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-08-04 15:02:17.819 App[329:22907] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2015-08-04 15:02:17.820 App[329:22907] The relevant UICollectionViewFlowLayout instance is <UICollectionViewLeftAlignedLayout: 0x157124290>, and it is attached to <UICollectionView: 0x1568aac00; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15713b5c0>; layer = <CALayer: 0x1570fab30>; contentOffset: {0, -64}; contentSize: {0, 0}> collection view layout: <UICollectionViewLeftAlignedLayout: 0x157124290>.
2015-08-04 15:02:17.820 App[329:22907] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-08-04 15:02:20.379 App[329:22907] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-08-04 15:02:20.379 App[329:22907] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2015-08-04 15:02:20.380 App[329:22907] The relevant UICollectionViewFlowLayout instance is <UICollectionViewLeftAlignedLayout: 0x157124290>, and it is attached to <UICollectionView: 0x1568aac00; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15713b5c0>; layer = <CALayer: 0x1570fab30>; contentOffset: {0, -64}; contentSize: {0, 0}> collection view layout: <UICollectionViewLeftAlignedLayout: 0x157124290>.
2015-08-04 15:02:20.380 App[329:22907] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-08-04 15:02:24.488 App[329:22907] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-08-04 15:02:24.489 App[329:22907] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2015-08-04 15:02:24.489 App[329:22907] The relevant UICollectionViewFlowLayout instance is <UICollectionViewLeftAlignedLayout: 0x157124290>, and it is attached to <UICollectionView: 0x1568aac00; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15713b5c0>; layer = <CALayer: 0x1570fab30>; contentOffset: {0, -64}; contentSize: {0, 0}> collection view layout: <UICollectionViewLeftAlignedLayout: 0x157124290>.
2015-08-04 15:02:24.489 App[329:22907] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-08-04 15:02:32.182 App[329:22907] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-08-04 15:02:32.182 App[329:22907] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2015-08-04 15:02:32.184 App[329:22907] The relevant UICollectionViewFlowLayout instance is <UICollectionViewLeftAlignedLayout: 0x157124290>, and it is attached to <UICollectionView: 0x1568aac00; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15713b5c0>; layer = <CALayer: 0x1570fab30>; contentOffset: {0, -64}; contentSize: {0, 0}> collection view layout: <UICollectionViewLeftAlignedLayout: 0x157124290>.
2015-08-04 15:02:32.184 App[329:22907] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-08-04 15:02:38.764 App[329:22907] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-08-04 15:02:38.764 App[329:22907] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2015-08-04 15:02:38.765 App[329:22907] The relevant UICollectionViewFlowLayout instance is <UICollectionViewLeftAlignedLayout: 0x157124290>, and it is attached to <UICollectionView: 0x1568aac00; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15713b5c0>; layer = <CALayer: 0x1570fab30>; contentOffset: {0, -64}; contentSize: {0, 0}> collection view layout: <UICollectionViewLeftAlignedLayout: 0x157124290>.
2015-08-04 15:02:38.765 App[329:22907] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-08-04 15:02:39.729 App[329:22907] Logging only once for UICollectionViewFlowLayout cache mismatched frame
2015-08-04 15:02:39.729 App[329:22907] UICollectionViewFlowLayout has cached frame mismatch for index path <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0} - cached value: {{nan, nan}, {inf, inf}}; expected value: {{nan, nan}, {inf, inf}}
2015-08-04 15:02:39.730 App[329:22907] This is likely occurring because the flow layout subclass UICollectionViewLeftAlignedLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

A quick follow up on this issue from my side...

We fixed the bug that was also reproductible on iOS 8 too. It was related to another library we used to render some kind of custom tab bar controller. The component was forwarding some appearance methods manually where it should not. This made our collection view rendering it's content too soon when the view controller was not even displayed. Since the view controller had a bad frame, the layoutAttributesForElementsInRect: was called with a wrong rect (with negative values) and the layoutAttributesForItemAtIndexPath: was stuck in an infinite loop trying to return a layout for negative indexPath.item.

Maybe some kind of safeguard could be added to layoutAttributesForItemAtIndexPath: if the item is negative with an assertion and a return nil.

I found by changing the springiness to false it stopped this warning:
self.collectionView.collectionViewLayout.springinessEnabled = NO

@Reedyuk It seems that there isn't a property called springinessEnabled in UICollectionViewLayout

@xilin - Ah yes, i was getting this error from using JSQMessagesView controller, where it has this property.

Tnx Reedyuk, I have the same issue and it fixed

Has this been resolved? Because I cant find 'springinessEnabled'.

My scenario:

  1. View Controller with the collection view.
  2. New View Controller gets pushed where a user can select items from a table.
  3. On each selection, the collection view (in the previous view controller) gets updated with the new items either through a block or a notification.

So it seems to happen when the view controller is not being shown on screen but being updated.

I see the above commit fixes it but it wasn't in the latest pod! Anyway we can get that pod updated? Much appreciated!

commented

Having the same issue. Can you please update cocoa pods?
UICollectionViewLeftAlignedLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them
Xcode 7.0 iOS 9

+1 would be great to get this in the latest cocoapods

Sorry guys, I'm not being a good maintainer... I shall release an update in 1 to 2 days. I've been quite busy lately 😞

Yo! I've merged #5, and released a new patch upgrade version.

pod 'UICollectionViewLeftAlignedLayout', '~> 1.0.1'

I will close the issue now, please feel free to reopen it if you are still having troubles.

I also opened a new issue: #6, please leave a comment there to share how you are using this library.

Thanks all for the patience!