Juanpe / SkeletonView

☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
MIT License
12.53k stars 1.1k forks source link

Fatal Exception: NSInternalInconsistencyException for UICollectionElementKindSectionFooter #395

Open Narek1994 opened 3 years ago

Narek1994 commented 3 years ago

Hi Thanks for this wonderfull lib. Sometimes I am getting this crash in crashlytics for UICollectionView.prepareSkeleton

here is the code which starts skeletion

self.mainView.collectionView.prepareSkeleton(completion: { _ in
                self.mainView.showAnimatedSkeleton()
            })

Fatal Exception: NSInternalInconsistencyException the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath (UICollectionElementKindSectionFooter,<NSIndexPath: 0xbcb9f6b8ffdbdea0> {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil (<UICollectionReusableView: 0x15104bab0; frame = (0 0; 0 0); layer = <CALayer: 0x280024840>>)

Actually my collectionVIew doesn't have a UICollectionElementKindSectionFooter, why it is trying to get that view? Thanks in advice.

Juanpe commented 3 years ago

Hi @Narek1994, let's me check it :)

Juanpe commented 3 years ago

@Narek1994, did you implement the method func collectionSkeletonView(_ skeletonView: UICollectionView, supplementaryViewIdentifierOfKind: String, at indexPath: IndexPath) -> ReusableCellIdentifier?

Narek1994 commented 3 years ago

@Juanpe Yep, I have implemented it, and now very rarely getting this crash Fatal Exception: NSInvalidArgumentException *** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: <NSIndexPath: 0x918d357277e373ed> {length = 2, path = 0 - 0}) in UICollectionView.prepareSkeleton(completion:) Could you please help me to find where it is trying to set nil? Thanks.

Juanpe commented 3 years ago

🤔 please, could you provide the full trace log?

Narek1994 commented 3 years ago

I am getting this in the live app, so firebase crashlytics just gives me this

Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x19640cc64 (Missing) 1 libobjc.A.dylib 0x1961350a8 (Missing) 2 CoreFoundation 0x1964d7b68 (Missing) 3 CoreFoundation 0x1964e5b00 (Missing) 4 CoreFoundation 0x196347130 (Missing) 5 UIKitCore 0x1b967edc8 (Missing) 6 UIKitCore 0x1b9683b78 (Missing) 7 UIKitCore 0x1b91bca3c (Missing) 8 UIKitCore 0x1b9682b34 (Missing) 9 UIKitCore 0x1b967bf8c (Missing) 10 UIKitCore 0x1b968475c (Missing) 11 dzainRelease 0x1030c0e18 UICollectionView.prepareSkeleton(completion:) + 78 (UICollectionView+CollectionSkeleton.swift:78) 12 dzainRelease 0x102b3bf58 closure #1 in MainFeedViewController.showSkeleton() + 164 (MainFeedViewController.swift:164) 13 dzainRelease 0x1029d57d8 thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>) 14 libdispatch.dylib 0x1960dfec0 (Missing) 15 libdispatch.dylib 0x1960e3398 (Missing) 16 libdispatch.dylib 0x1960f5b7c (Missing) 17 libdispatch.dylib 0x1960ee200 (Missing) 18 CoreFoundation 0x1963ced28 (Missing) 19 CoreFoundation 0x19638d73c (Missing) 20 CoreFoundation 0x19638c5e8 (Missing) 21 HIToolbox 0x19e2a72a0 (Missing) 22 HIToolbox 0x19e2a7014 (Missing) 23 HIToolbox 0x19e2a6dd4 (Missing) 24 AppKit 0x198b7b480 (Missing) 25 AppKit 0x198b79e20 (Missing) 26 AppKit 0x198b6bcac (Missing) 27 AppKit 0x198b3d71c (Missing) 28 AppKit 0x198e2ceb4 (Missing) 29 UIKitMacHelper 0x1a929432c (Missing) 30 UIKitCore 0x1b9146610 (Missing) 31 libswiftUIKit.dylib 0x1cb24c788 (Missing) 32 dzainRelease 0x1029cbb30 main (BadgeAlertViewModel.swift) 33 libdyld.dylib 0x1962ad450 (Missing)

and the main crash message, which I have sent to you. Thanks.

Narek1994 commented 3 years ago

I can say, that during this, screen which should show Skeletion animation is not visible(another view controller is presented on it), can this be an issue?

Juanpe commented 3 years ago

I can say, that during this, screen which should show Skeletion animation is not visible(another view controller is presented on it), can this be an issue?

Then, what is the flow? The view appears, show the skeleton and presents a modal?

Narek1994 commented 3 years ago

View appears, presents a modal, on that modally presented controller there is an action which forces the main view to rerequest the data from backend and show Skeletion animation during that loading, I am showing Skeletion in this case because user can close the modally presented controller and he should see Skeletion animation if request is not finished yet.