diff --git a/src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs b/src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs index ee44a126571b..d4f994bb2397 100644 --- a/src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs +++ b/src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs @@ -41,7 +41,10 @@ protected override void DisconnectHandler(UIView platformView) { ItemsView.ScrollToRequested -= ScrollToRequested; _layout = null; - Controller?.DisposeItemsSource(); + MauiContext?.GetDispatcher()?.Dispatch(() => + { + Controller?.DisposeItemsSource(); + }); base.DisconnectHandler(platformView); } diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs index 8b89af8bcdd8..77a5f631876e 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs @@ -203,6 +203,7 @@ void Items.MauiCollectionView.ICustomMauiCollectionViewDelegate.MovedToWindow(UI DetachingFromWindow(); } } + internal void DisposeItemsSource() { ItemsSource?.Dispose(); diff --git a/src/Core/tests/DeviceTests.Shared/MauiProgramDefaults.cs b/src/Core/tests/DeviceTests.Shared/MauiProgramDefaults.cs index a99ca72d0133..5fbb78d95724 100644 --- a/src/Core/tests/DeviceTests.Shared/MauiProgramDefaults.cs +++ b/src/Core/tests/DeviceTests.Shared/MauiProgramDefaults.cs @@ -66,6 +66,16 @@ public static MauiApp CreateMauiApp(List testAssemblies) { RequiresUIContext = true, }); +#endif + +#if IOS || MACCATALYST + + appBuilder.ConfigureMauiHandlers(handlers => + { + handlers.AddHandler(); + handlers.AddHandler(); + }); + #endif appBuilder.UseVisualRunner();