[iOS 18] Grouped CollectionView with header template and templateselector crashes immediately on iOS 18, works on iOS 17
Description
I've released my Maui app on App Store with multiple grouped CollectionView being used for different screens and it has been working fine till now on all iOS version, except the latest iOS 18. As customers have upgraded to iOS 18, and they're trying to use our app in iOS 18, it just keep crashing immediately as the landing page of the app has Grouped CollectionView implemented with TemplateSelector for different cell designs and it is one of the main page of the app. It is throwing this exception:
Unhandled managed exception: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view: <Microsoft_Maui_Controls_Handlers_Items_VerticalSupplementaryView: 0x11907c600; baseClass = UICollectionViewCell; frame = (0 0; 0 0); alpha = 0; layer = <CALayer: 0x30b09c8a0>>; Collection view: <Microsoft_Maui_Controls_Handlers_Items_MauiCollectionView: 0x1179fea00; baseClass = UICollectionView; frame = (0 0; 390 669); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x303758900>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x307d03e00>; contentOffset: {0, 0}; contentSize: {390, 1464}; adjustedContentInset: {0, 0, 0, 0}; layout: <Microsoft_Maui_Controls_Handlers_Items_GridViewLayout: 0x11ca79900>; dataSource: <Microsoft_Maui_Controls_Handlers_Items_ReorderableItemsViewController_1: 0x11aff5400>>
(ObjCRuntime.ObjCException) at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2708 at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 64 at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 96
I've upgraded the MacOS to Mac Sequoia 15.0.1 and Xcode to 16, so now cannot downgraded to using Xcode 15.4. And infact I've release the app to store using Xcode 15.4 before this upgrade, but still it was crashing in iOS 18 devices.
I've also tried now to upgrade the MAUI packages to latest version to check if there's any fix for this issue in the latest MAUI version but still it's crashing.
We're completely stuck as the app is live on store and customers are reporting this issue and not able to use the app at all, so it's quite embarrassing and bad impression for the company as a provider. We need a fix for this ASAP.
Steps to Reproduce
- Create a new MAUI app or use an existing app with Groped CollectionView which uses TemplateSelector for cell designs
- Run and install the app on iOS 18 device or simulator
- The app crashes immediately on the CollectionView with the above mentioned exception.
Link to public reproduction project repository
No response
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.40 SR5
Affected platforms
iOS
Affected platform versions
iOS 18.0.1
Did you find any workaround?
Didn't find any workaround yet. Have tried upgrading the nuget packages to latest versions but that also didn't work.
Relevant log output
Unhandled managed exception: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view: <Microsoft_Maui_Controls_Handlers_Items_VerticalSupplementaryView: 0x11907c600; baseClass = UICollectionViewCell; frame = (0 0; 0 0); alpha = 0; layer = <CALayer: 0x30b09c8a0>>; Collection view: <Microsoft_Maui_Controls_Handlers_Items_MauiCollectionView: 0x1179fea00; baseClass = UICollectionView; frame = (0 0; 390 669); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x303758900>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x307d03e00>; contentOffset: {0, 0}; contentSize: {390, 1464}; adjustedContentInset: {0, 0, 0, 0}; layout: <Microsoft_Maui_Controls_Handlers_Items_GridViewLayout: 0x11ca79900>; dataSource: <Microsoft_Maui_Controls_Handlers_Items_ReorderableItemsViewController_1: 0x11aff5400>>
(ObjCRuntime.ObjCException) at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2708 at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 64 at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 96
We've found some similar issues:
- #25139 , similarity score: 84%
If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.
Note: You can give me feedback by 👍 or 👎 this comment.
I've tried with the .NET 8 latest version 8.0.403/8.0.10 which is the last version available for .NET 8 but still didn't help at all with this issue and I'm still getting the same crash and exception.
Same problem here. Works great on Droid. Crashes on IOS
ObjCRuntime.ObjCException: 'Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view: <Microsoft_Maui_Controls_Handlers_Items_VerticalSupplementaryView: 0x127bc0c00; baseClass = UICollectionViewCell; frame = (0 0; 0 0); alpha = 0; layer = <CALayer: 0x304105c60>>; Collection view: <Microsoft_Maui_Controls_Handlers_Items_MauiCollectionView: 0x114649c00; baseClass = UICollectionView; frame = (0 0; 375 132.5); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x300889050>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x3040c8460>; contentOffset: {0, 0}; contentSize: {375, 133}; adjustedContentInset: {0, 0, 0, 0}; layout: <Microsoft_Maui_Controls_Handlers_Items_ListViewLayout: 0x114568a00>; dataSource: <Microsoft_Maui_Controls_Handlers_Items_ReorderableItemsViewController_1: 0x11451a800>> Native stack trace: 0 CoreFoundation 0x000000018a64d098 4250D45C-51A9-3AC5-8C3D-69DE936FAD46 + 540824 1 libobjc.A.dylib 0x000000018794f2e4 objc_exception_throw + 88 2 Foundation 0x0000000189a1e15c 6D058A2D-05CF-3A29-8BEB-B1030AE97282 + 8528220 3 UIKitCore 0x000000018d784d44 187C890E-8E4C-32F2-A97E-FA905A55F094 + 10423620 4 UIKitCore 0x000000018debe1e4 187C890E-8E4C-32F2-A97E-FA905A55F094 + 17998308 5 UIKitCore 0x000000018cf4ccac 187C890E-8E4C-32F2-A97E-FA905A55F094 + 1805484 6 UIKitCore 0x000000018d0a53c4 187C890E-8E4C-32F2-A97E-FA905A55F094 + 3216324 7 UIKitCore 0x000000018cda4248 187C890E-8E4C-32F2-A97E-FA905A55F094 + 66120 8 QuartzCore 0x000000018c0e9630 E592F77A-3E20-3854-96AB-4CEDCA39FFF7 + 493104 9 QuartzCore 0x000000018c0e91bc E592F77A-3E20-3854-96AB-4CEDCA39FFF7 + 491964 10 QuartzCore 0x000000018c140268 E592F77A-3E20-3854-96AB-4CEDCA39FFF7 + 848488 11 QuartzCore 0x000000018c0bf0a0 E592F77A-3E20-3854-96AB-4CEDCA39FFF7 + 319648 12 QuartzCore 0x000000018c102364 E592F77A-3E20-3854-96AB-4CEDCA39FFF7 + 594788 13 UIKitCore 0x000000018ce42848 187C890E-8E4C-32F2-A97E-FA905A55F094 + 714824 14 UIKitCore 0x000000018ce3fe44 187C890E-8E4C-32F2-A97E-FA905A55F094 + 704068 15 UIKitCore 0x000000018ce3fcb8 187C890E-8E4C-32F2-A97E-FA905A55F094 + 703672 16 UIKitCore 0x000000018ce3f908 187C890E-8E4C-32F2-A97E-FA905A55F094 + 702728 17 UIKitCore 0x000000018ce4087c 187C890E-8E4C-32F2-A97E-FA905A55F094 + 706684 18 CoreFoundation 0x000000018a620088 4250D45C-51A9-3AC5-8C3D-69DE936FAD46 + 356488 19 CoreFoundation 0x000000018a62001c 4250D45C-51A9-3AC5-8C3D-69DE936FAD46 + 356380 20 CoreFoundation 0x000000018a61db6c 4250D45C-51A9-3AC5-8C3D-69DE936FAD46 + 346988 21 CoreFoundation 0x000000018a61cd04 4250D45C-51A9-3AC5-8C3D-69DE936FAD46 + 343300 22 CoreFoundation 0x000000018a61c5b8 CFRunLoopRunSpecific + 572 23 GraphicsServices 0x00000001d60b21c4 GSEventRunModal + 164 24 UIKitCore 0x000000018d1722c0 187C890E-8E4C-32F2-A97E-FA905A55F094 + 4055744 25 UIKitCore 0x000000018d220ddc UIApplicationMain + 340 26 DSDRouteManager 0x00000001031f476c xamarin_UIApplicationMain + 60 27 DSDRouteManager 0x00000001035dcd80 AppleCryptoNative_X509ImportCollection + 3379532 28 DSDRouteManager 0x00000001035db680 AppleCryptoNative_X509ImportCollection + 3373644 29 DSDRouteManager 0x00000001035d0090 AppleCryptoNative_X509ImportCollection + 3327068 30 DSDRouteManager 0x00000001035cdc28 AppleCryptoNative_X509ImportCollection + 3317748 31 DSDRouteManager 0x0000000103592240 AppleCryptoNative_X509ImportCollection + 3073548 32 DSDRouteManager 0x000000010352ddc0 AppleCryptoNative_X509ImportCollection + 2662796 33 DSDRouteManager 0x0000000103535320 AppleCryptoNative_X509ImportCollection + 2692844 34 DSDRouteManager 0x00000001035988a8 AppleCryptoNative_X509ImportCollection + 3099764 35 DSDRouteManager 0x0000000103234f9c xamarin_get_original_working_directory_path + 4356 36 DSDRouteManager 0x00000001036117d4 AppleCryptoNative_X509ImportCollection + 3595168 37 dyld 0x00000001afdf0d34 5DB83988-2EE6-3756-BD07-B8D67B1133A5 + 212276 '
Looks like this should be fixed with .NET MAUI 8.0.92, please try that one and let us know if that helps?
I'm still getting the same problem on both an iPhone 7 running 18.01 and a sim running 17.2. Here are my packages
"Microsoft.Maui.Controls" Version="8.0.92"
"Microsoft.Maui.Controls.Compatibility" Version="8.0.92"
"Microsoft.Maui.Essentials" Version="8.0.92"
"Prism.Maui" Version="9.0.537"
Seems to only happen on a collection view with grouped header. My other collection views are working fine. Visual Studio Community 17.11.5
Do you have a reproduction for me? Because I just tried this in our sample app here in the repository, go to the grouped CollectionView page and it all seems to work fine, so there seems to be something specific to your case that seems to be going wrong.
I created a test project and found my problem while doing it. I was using an ObservableCollection. I changed it to a List and it works fine now. Apparently Android doesn't care but it causes IOS to throw a fit. This is only for a Grouped CollectionView, all other CollectionViews work fine. I don't feel too bad though, even ChatGPT didn't have a solution :)
I have the same problem, but I'm using a Telerik RadListView instead of a standard CollectionView. I also tried to change the source to List instead of ObservableCollection, but that didn't help. Maybe Telerik is converting it under the hood to an ObservableCollection. However, IMHO it should of course be possible to use an ObservableCollection as source.
It works fine on Android but crashes on iOS. I'm also using 8.0.92 Telerik.UI.for.Maui Version=7.1.0
@jfversluis Here is the test app I created if it helps any. In InvoiceContentViewModel.cs just change the List<T> to an ObservableCollection and it will recreate the issue.GroupedCollectionTest.zip
This issue can be reproduced at iOS platform on the latest 17.13 Preview 1(8.0.100 &8.0.92).
Any update on this? Completely blocked
In general iOS18 has a problem with collection views, especially with GroupHeaderTemplate... On android app works perfectly fine.
@jfversluis If we can replace the CarouselView (ie. CollectionView; but in my case it's the CarouselView that is broken) with your SwipeCardView, that would be great. However, I cannot figure out how to (or if possible) reverse the loop in SwipeCardView so swiping left goes to the previous item.
Sidenote: I updated my app to .NET9 and all associated nuget packages to 9.x.x.