diff --git a/src/Controls/src/Core/Handlers/Items/iOS/SelectableItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/SelectableItemsViewController.cs index 6e372b55eba3..d182b578224a 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/SelectableItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/SelectableItemsViewController.cs @@ -25,12 +25,22 @@ protected override UICollectionViewDelegateFlowLayout CreateDelegator() // _Only_ called if the user initiates the selection change; will not be called for programmatic selection public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) { + if (indexPath is null || indexPath.Handle == IntPtr.Zero) + { + return; + } + FormsSelectItem(indexPath); } // _Only_ called if the user initiates the selection change; will not be called for programmatic selection public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath) { + if (indexPath is null || indexPath.Handle == IntPtr.Zero) + { + return; + } + FormsDeselectItem(indexPath); } @@ -39,6 +49,11 @@ internal void SelectItem(object selectedItem) { var index = GetIndexForItem(selectedItem); + if (index is null || index.Handle == IntPtr.Zero) + { + return; + } + if (index.Section > -1 && index.Item > -1) { // Ensure the selected index is updated after the collection view's items generation is completed diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs index fb83ce09d755..654533e8093d 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/SelectableItemsViewController2.cs @@ -25,12 +25,22 @@ protected override UICollectionViewDelegateFlowLayout CreateDelegator() // _Only_ called if the user initiates the selection change; will not be called for programmatic selection public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) { + if (indexPath is null || indexPath.Handle == IntPtr.Zero) + { + return; + } + FormsSelectItem(indexPath); } // _Only_ called if the user initiates the selection change; will not be called for programmatic selection public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath) { + if (indexPath is null || indexPath.Handle == IntPtr.Zero) + { + return; + } + FormsDeselectItem(indexPath); } @@ -39,6 +49,11 @@ internal void SelectItem(object selectedItem) { var index = GetIndexForItem(selectedItem); + if (index is null || index.Handle == IntPtr.Zero) + { + return; + } + if (index.Section > -1 && index.Item > -1) { // Ensure the selected index is updated after the collection view's items generation is completed