IGListKit: Cells not showing up after reloadData

New issue checklist

General information

Hey guys,

Firstly, I adore this library. Amazing job! So I am probably doing something wrong, but here goes.

I have a toggle button that filters objects based on a Bool. Within the DataSource I have:

public func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
        guard let delegate = delegate else { return [] }
        
        var objects = !isFeatured ? delegate.model.posts as [IGListDiffable] : delegate.model.featuredPosts as [IGListDiffable]

model.featuredPosts is a simple filter:

var featuredPosts: [Post] {
        get {
            return posts.filter { $0.isFeatured }
        }
}

Within my delegate I am reloading that data with:

adapter.reloadData { (completed) in
    print(completed)
}

When I toggle to only show isFeatured posts, the collection view updates as expected and I see 3 items. When I toggle it again to show all posts (8 in total), I can see it requesting the sections and cells, however the collection view isn’t updated.

When I update the completion block as:

adapter.reloadData(completion: { (completed) in
            self.adapter.performUpdates(animated: false, completion: nil)
            print(completed)
            print(self.adapter.collectionView?.numberOfSections)
 })

I can see the correct number of sections being printed (8), but not displayed.

Any suggestions on what I may be doing wrong?

For what it’s worth the collection view frame is being set:

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        collectionView.frame = view.bounds
}

Thanks in advance, Steve

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Some tips with debugging the collection view:

(lldb) p (int)[collectionView numberOfSections]
(lldb) p (int)[collectionView numberOfItemsInSection:0] // do for each section
(lldb) po [collectionView recursiveDescription] // see if the cells are in the hierarchy

Also to get info on the backing store of the IGListAdapter:

(lldb) [adapter objects]
(lldb) [[adapter sectionMap] sectionControllerToObjectMap]
(lldb) [[adapter sectionMap] sectionControllerToSectionMap]

Makes me want to work on some debugging tools for IGListKit…

Thanks @rnystrom - unfortunately there are a few cells that do use AL (PostCaptionCell) for one, so unfortunately removing it causes some layout issues. That being said Jeff’s work-around is working just great for me, so there’s no rush on the bug fix on my account.

Thanks again for your response and looking into this, IGListKit is just awesome.

Thanks @rnystrom - glad to be able to help. Awesome news that it’ll be fixed for 2.0.1, for now I will use @jeffbailey 's workaround.

I run into a similar issue when I first started using IGListKit. I’m filtering a list based on text typed into a search bar. Sometimes the number of items shown in the collection view would not be correct when the item count increased based on the new filter text. Reloading twice fixed the issue as @stevejcox said. Also rotating the device caused the correct number of items to display. However, I realized I really wanted to be calling performUpdates instead of reloadData to get a nice animation:

adapter.performUpdates(animated: true, completion: nil)

I never did get to the bottom of the reloadData issue.