ivnsch/ChartLegends

NSInternalInconsistencyException - Cant have ChartLegends embedded in a collection view

Closed this issue · 6 comments

I get a couple different errors based on trying to get this working inside a collection view that i am using as a carousel of cards of charts.

if I try to use the default setLegends in the example I get this:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier TextLabelChartLegendCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

If I try to use a custom cell I get this:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier DemandByStackedCardCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

Thanks for reporting. I'll check as soon as I have time... probably the coming weekend. In the meantime, feel free to investigate it, the library should be fairly simple to debug...

I get the same Problems with using the Legends within an UIScrollView. Is there a solution yet?

Evidently not, but as mentioned before feel free to give it a look, the library is quite small and should be understandable... the legends are a collection view so there shouldn't be anything particularly mysterious going on. otherwise I'll try to do this soon, sorry, very busy these days.

ChartLegendsView.swift, line 170:

fileprivate func register(cellType: CellType) {
        let frameworkBundleId = "com.schuetz.ChartLegends"
        if Bundle.main.path(forResource: cellType.reuseIdentifier, ofType: "nib") != nil {
            collectionView?.register(UINib(nibName: cellType.reuseIdentifier, bundle: nil), forCellWithReuseIdentifier: cellType.reuseIdentifier)
        } else if Bundle(identifier: frameworkBundleId)?.path(forResource: cellType.reuseIdentifier, ofType: "nib") != nil {
            collectionView?.register(UINib(nibName: cellType.reuseIdentifier, bundle: Bundle(identifier: frameworkBundleId)), forCellWithReuseIdentifier: cellType.reuseIdentifier)
        }
    }

These NIB files are not actually included in the ChartLegends bundle, so the if conditions always fail, and collectionView.register() is never called. This creates a crash with 100% frequency and renders the basic ChartLegends workflow unusable.
The missing NIB files are present in the example project's copy of the ChartLegends source. I tried manually copying them over to my project. Then, I got a different crash — something about a class not being compliant for a selector.

Well, I don't have time, but I'm quick at merging pull requests :)

Fixed in 0.0.5