apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.
MIT License
1.35k stars 161 forks source link

Crash on iOS 15 occurs when sections do not have a .sectionHeader #221

Closed sjmueller closed 3 years ago

sjmueller commented 3 years ago

In iOS 15, a crash occurs in some circumstances when a .sectionHeader is not provided:

the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath: does not match the element kind it is being used for. When asked for a view of element kind 'UICollectionElementKindSectionHeader' the data source dequeued a view registered for the element kind 'A2E5C23F-9496-4722-A001-F258D15C2873

and this particular code is hit:

image

This crash only occurs in iOS15, as the exact code does not crash in iOS14. More details can be found here:

https://developer.apple.com/forums/thread/682570

I was able to workaround the issue in my codebase by adding a dummy section header to each section:

.sectionHeader {
    EmptyView()
}

I believe this is critical in nature because without action, many apps hitting this codepath will start crashing on September 20 when iOS 15 is made available to the general public.

Thomas-Vos commented 3 years ago

Similar issue for me after upgrading to Xcode 13.0 and running the app on iOS 15:

the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath: does not match the element kind it is being used for. When asked for a view of element kind 'UICollectionElementKindSectionFooter' the data source dequeued a view registered for the element kind '7D3B1B07-7B46-449D-B7A2-E243CC0D9D98

In my case I was able to workaround the issue by adding the following:

.sectionFooter {
    EmptyView()
}
mycroftcanner commented 3 years ago

what did you add it to?

Thomas-Vos commented 3 years ago

I added it to one of the ASCollectionViewSections in my code. I only needed to add it to one, but that could be different for you.

Thomas-Vos commented 3 years ago

Also (depending on the error message) you may need to add either an empty header or an empty footer.

apptekstudios commented 3 years ago

Thanks for posting about this crash. It sounds like new behaviour on iOS 15 is enforcing that the same class of cell is always used for each supplementary type. Unfortunately I'm on holiday without a laptop so can't test but I think it will be a single line fix.

apptekstudios commented 3 years ago

Thanks for posting about this crash. It sounds like new behaviour on iOS 15 is enforcing that the same class of cell is always used for each supplementary type. Unfortunately I'm on holiday without a laptop so can't test but I think it will be a single line fix.

As I said no computer to test, but replacing the supplementaryEmptyKind with just kind on line 87 here should hopefully fix that crash.

YunusDeveloper commented 3 years ago
image

I cha

Thanks for posting about this crash. It sounds like new behaviour on iOS 15 is enforcing that the same class of cell is always used for each supplementary type. Unfortunately I'm on holiday without a laptop so can't test but I think it will be a single line fix.

As I said no computer to test, but replacing the supplementaryEmptyKind with just kind on line 87 here should hopefully fix that crash.

I changed but I does not work. It says "Thread 1: "could not dequeue a view of kind: UICollectionElementKindSectionHeader with identifier 9DC51136-3548-42CA-9156-5FEDEFB485DA - must register a nib or a class for the identifier or connect a prototype cell in a storyboard"

apptekstudios commented 3 years ago

Fixed: V2.1.1

Please let me know if this does not solve the issue for you, I tested multiple cases and could no longer reproduce any crash with the new version :)

yusufonderd commented 3 years ago

Hello, How can I install version 2.1.1 of library with pod ? When I'm adding to pod 'ASCollectionView-SwiftUI' in my podfile. Library version still looking in 1.7.1.

berry95 commented 3 years ago

스크린샷 2021-10-01 오후 8 49 17

Crash seems to have been fixed, but unknown insets appread on 15.0. You can check it in the official instafeed demo.