Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSInternalInconsistencyException when scrolling to the bottom #18

Closed
andreamazz opened this issue Aug 7, 2014 · 17 comments
Closed

NSInternalInconsistencyException when scrolling to the bottom #18

andreamazz opened this issue Aug 7, 2014 · 17 comments

Comments

@andreamazz
Copy link
Contributor

Hi James.
I'm struggling with an issue... I'm using your library in a collection view, and I noticed that sometimes the system raises an NSInternalInconsistencyException when scrolling to the bottom. It looks like it's correlated to the amount of cells displayed. I was able to recreate the issue in your sample, by providing only 2 sections, the first one with one item, the second one with 4. (You can find the sample in my fork).
Here's the catch: it only happens when I compile with Xcode 5.1 on an iOS8 device (beta5). If I compile with Xcode6 everything goes smoothly. Given the circumstances it might not even be worth spending too much time fixing this, as it's probably a bug introduced in the latest beta, but if someone with the current iOS8 beta downloads an app from the store with this component, it might crash.
Here's the full stack trace:

2014-08-07 16:03:14.718 CSStickyHeaderFlowLayoutDemo[1538:270805] 
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
 reason: 'layout attributes for supplementary item at index path (<NSIndexPath: 0x1a07c410> {length = 2, path = 1 - 0}) 
changed from <CSStickyHeaderFlowLayoutAttributes: 0x16d4a050> index path: (<NSIndexPath: 0x1a08e4c0> {length = 2, path = 1 - 0}); 
element kind: (UICollectionElementKindSectionHeader); 
frame = (0 330; 320 50); 
zIndex = 1024;  
to <CSStickyHeaderFlowLayoutAttributes: 0x1a097e80> index path: (<NSIndexPath: 0x1a07c410> {length = 2, path = 1 - 0}); 
element kind: (UICollectionElementKindSectionHeader); 
frame = (0 278.5; 320 50); 
zIndex = 1024;  without invalidating the layout'

anyway, thanks for your great work. 👍
Cheers.

@jamztang
Copy link
Collaborator

Thanks for reporting Andrea, In fact I'm not really sure what cause the problem at this moment, I was hoping #15 had fixed the crash. I'll keep an eye on it, if couldn't find anything wrong, hopefully when iOS 8 stables it could resolve itself.

@jacobmoncur
Copy link

I've had the same issue recently pretty consistently on Xcode GM iOS 8:

Fatal Exception: NSInternalInconsistencyException
layout attributes for supplementary item at index path (<NSIndexPath: 0x15818370> {length = 2, path = 0 - 0}) changed from 
<CSStickyHeaderFlowLayoutAttributes: 0x147476e0> index path: (<NSIndexPath: 0x14747770> {length = 2, path = 0 - 0}); 
element kind: (CSStickyHeaderParallexHeader); frame = (0 -64; 320 109); to 
<CSStickyHeaderFlowLayoutAttributes: 0x158182e0> index path: (<NSIndexPath: 0x15818370> {length = 2, path = 0 - 0}); 
element kind: (CSStickyHeaderParallexHeader); frame = (0 0; 320 45); without invalidating the layout

Any ideas on what is causing this??

@laynemoseley
Copy link

I'm seeing the same thing....

@jamztang
Copy link
Collaborator

So I'm using Xcode 6 GM, looking at it seems the fork from @andreamazz doesn't reproduce the warning again.
@jacobmoncur @laynemoseley can you guys put up an example so we can look into it?

@jacobmoncur
Copy link

@jamztang I think we found the issue. The crash comes when the translucent property of the navigation bar is toggled.

self.navigationController.navigationBar.translucent = <NO,YES>;

If you change the translucent property of the UINavigationBar as you navigate the UINavigationController the offset of the UICollectionView changes (if not translucent the offset is 0, if translucent its -64) and causes the Inconsistency when the header attributes are getting created and are laying out. To ensure that it doesn't crash you need to make sure that translucent property of the UINavigationBar is the same when you enter/exit the UIViewController that has your UICollectionView.

@jamztang
Copy link
Collaborator

@jacobmoncur didn't quite able to reproduce the problem. Do you toggle translucent in viewWillAppear?

@markst
Copy link

markst commented Oct 8, 2014

Also getting a similar issue when attempting to get an index path of a targetContentOffset.

i.e:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
                     withVelocity:(CGPoint)velocity
              targetContentOffset:(inout CGPoint *)targetContentOffset
{
    CGPoint lastCellTargetOffset = * targetContentOffset;
    lastCellTargetOffset.y += CGRectGetHeight(scrollView.frame) ;
    NSIndexPath * targetIndexPath = [(UICollectionView *)scrollView indexPathForItemAtPoint:lastCellTargetOffset];
}

and I get:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'layout attributes for supplementary item at index path (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) changed from <CSStickyHeaderFlowLayoutAttributes: 0x7ffc86634570> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 91888.5; 375 50); non-affine transform;  to <CSStickyHeaderFlowLayoutAttributes: 0x7ffc861dc6b0> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 90004; 375 50); non-affine transform;  without invalidating the layout'

@oks
Copy link

oks commented Oct 15, 2014

Still no solution?

@jamztang
Copy link
Collaborator

I tried @andreamazz branch again but I am not able to reproduce the problem. I didn't have a chance to setup or replicate the proper testing environment that triggers the bug yet, if there's any help would be highly appreciated.

@andreamazz
Copy link
Contributor Author

Looks like that compiling with the latest SDK solves the issue, right now I can't reproduce the crash either.

@jamztang
Copy link
Collaborator

jamztang commented Nov 3, 2014

Great so lets close this for now and until there're new issues arise.

@jamztang jamztang closed this as completed Nov 3, 2014
@seedante
Copy link

I get same issue when implementing timeline layout and I fix it. I can reproduce the issue in my demo easily. Actually, the exception has told us what happen. When scrolling to bottom, people always continue to scroll to beyond the contentSize and CollectionView will go back. In the process, layout system will call layoutAttributesForElementsInRect: for two different rect, if any layoutAttributes changed its property, you will get this exception. That's what exception means. I hope this can help.

@kapilrathore
Copy link

hey i am having some issue with the indexpath creating please help indexPath = [NSIndexPath indexPathForItem:1 inSection:1];

@tony-boxed
Copy link

any real solution on this? 2 years later and this is still happening.

@monzy613
Copy link

monzy613 commented Jul 8, 2016

iOS 10 beta2, happen this problem

@cooler333
Copy link

cooler333 commented Aug 3, 2016

+1 (Swift)

I've to remove CSStickyHeaderFlowLayout only for this error!!!
and use this:

if #available(iOS 9.0, *) {
    (collectionView.collectionViewLayout as! UICollectionViewFlowLayout).sectionHeadersPinToVisibleBounds = true
}
  • Storyboard + Header + Cells
  • UICollectionView in UIViewController
  • CSStickyHeaderFlowLayout as class of collectionView -> layout in Storyboard
  • Autosized cells
  • Translucent NavBar + TabBar
self.automaticallyAdjustsScrollViewInsets = false
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    let width = floor((collectionView.frame.size.width - 1.0) / 2.0)
    return CGSize(width: width, height: width)
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
    let width = floor(collectionView.frame.size.width)
    return CGSize(width: width, height: 50)
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
    return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
    return 1.0
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
    return 1.0
}

@drewg233
Copy link

drewg233 commented Jan 7, 2017

Add this to your viewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()
    if #available(iOS 10.0, *) {
        self.collectionView?.isPrefetchingEnabled = false
    } else {
        //Fallback on earlier versions
    }
}

Found by @chriscohoat here: #144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests