CSStickyHeaderFlowLayout: NSInternalInconsistencyException when scrolling to the bottom

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.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (1 by maintainers)

Commits related to this issue

Most upvoted comments

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: https://github.com/CSStickyHeaderFlowLayout/CSStickyHeaderFlowLayout/issues/144

+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
}