Skip to content
This repository was archived by the owner on Mar 26, 2019. It is now read-only.
This repository was archived by the owner on Mar 26, 2019. It is now read-only.

Crash on collectionView.deleteSections(...) #7

Open

Description

@ostatnicky

If I add a button that is removing some section, it is crashing after scrolling to last section:

@IBAction func didClick(sender: AnyObject) {
        numberOfSections -= 1;
        let set = NSIndexSet(index: 2)
        self.collectionView.deleteSections(set)
    }

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView received layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0xc000000000003116> {length = 2, path = 49 - 0}'

Can you help me how to resolve this issue?

Activity

  1. ostatnicky commented on Sep 29, 2015

    @ostatnicky
    Author
  2. ostatnicky commented on Sep 29, 2015

    @ostatnicky
    Author

    I added

    func reload() {
            itemAttributes = nil
            itemsSize = nil
            prepareLayout()
        }
    

    into CustomCollectionViewLayout and call it after deleting section, but it's still crashing when I'm on bottom of collection view.

  3. ostatnicky commented on Sep 30, 2015

    @ostatnicky
    Author

    Hey, I've niled at start of prepareLayout the itemAttributes and itemsSize and it works now. It is a little hot fix but it works.

        override func prepareLayout() {
    
            itemAttributes = nil
            itemsSize = nil
    ...
    
  4. jkereako commented on Aug 5, 2016

    @jkereako

    @ostatnicky UICollectionViewLayout has a delegate method just for what you're doing.

    override func invalidateLayout() {
      super.invalidateLayout()
    
      itemAttributes = nil
      itemsSize = nil
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions