Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.87k stars 1.54k forks source link

Unable to Utilize SizeForItem and CellForItem Function #1558

Open phonix-dev opened 2 years ago

phonix-dev commented 2 years ago

New issue checklist

General information

Debug information

# Please include debug logs using the following lldb command:
po [IGListDebugger dump]

I'm still having a weird bug. Everything compiles and runs but CellForItem(at index: Int) && sizeForItem(at index: Int) aren't working within ListSectionControllers. I put breakpoints on numberOfItems() function and can see that is working but the rest are not responding

popoolasubomi commented 2 years ago

I figured out the issue, for anyone else needing help regarding this topic, Here's the what fixed the bug for me: external documentation provided this initialization format for UICollectionView

    public var collectionView: UICollectionView = {
        return UICollectionView(
            frame: .zero,
            collectionViewLayout: UICollectionViewFlowLayout()
        )
    }()

It was hard to catch this error because this worked normally until i had to cut and divide my code piece by piece to trace inconsistencies with a test project that worked. (I do not know why this didn't work because it seems like the standard procedure in initializing views) I referred to a direct method of initializing UICollectionView

    public var collectionView = UICollectionView(
        frame: .zero,
        collectionViewLayout: UICollectionViewFlowLayout()
    )

and that worked for me.

Also your adapter should be a class property incase you missed that, that could be a possible bug Please refer to link for more info on the bug related to "adapter and class property"