roubachof / Sharpnado.CollectionView

A performant list view supporting: grid, horizontal and vertical layout, drag and drop, and reveal animations.
The Unlicense
245 stars 30 forks source link

Fix System.ObjectDisposedException #36

Closed AlleSchonWeg closed 3 years ago

AlleSchonWeg commented 3 years ago

Fixes {System.ObjectDisposedException: Cannot access a disposed object.Object name: 'UIKit.UICollectionView'. It happens if you have the listview in a grid and you need to move the listview to another cell. If you rotate the device for example. Because myGrid.Children.Remove(listview) calls dispose on iOSHorizontalListViewRenderer. And when _collectionView != null no new instance is creating and app will crash at SetNativeControl(_collectionView).

Exception StackTrace:

at ObjCRuntime.ThrowHelper.ThrowObjectDisposedException (System.Object o) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/ThrowHelper.cs:34 at ObjCRuntime.NativeObjectExtensions.GetNonNullHandle (ObjCRuntime.INativeObject self, System.String argumentName) [0x0001b] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/INativeObject.cs:29 at UIKit.UIView.AddSubview (UIKit.UIView view) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIView.g.cs:240 at Xamarin.Forms.Platform.iOS.ViewRenderer`2[TView,TNativeView].SetNativeControl (TNativeView uiview) [0x00047] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ViewRenderer.cs:240 at Sharpnado.HorizontalListView.iOS.Renderers.HorizontalList.iOSHorizontalListViewRenderer.SetCollectionView (UIKit.UICollectionView collectionView) [0x00000] in D:\Dev\Sharpnado\src\Sharpnado.HorizontalListView\Sharpnado.HorizontalListView.iOS\Renderers\HorizontalList\iOSHorizontalListViewRenderer.cs:215 at Sharpnado.HorizontalListView.iOS.Renderers.HorizontalList.iOSHorizontalListViewRenderer.LayoutSubviews () [0x00075] in D:\Dev\Sharpnado\src\Sharpnado.HorizontalListView\Sharpnado.HorizontalListView.iOS\Renderers\HorizontalList\iOSHorizontalListViewRenderer.cs:61 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:69

AlleSchonWeg commented 3 years ago

@roubachof Could you release a new nuget with this fix? Thank you