I have a .net MAUI project that I am working on, and I am wondering how one would go about getting an index from an array of objects as an integer and then somehow load it into an NSIndexPath object on iOS to be read within the ReloadItems() method for my application’s UICollectionView. I m trying to build this to use as work around for a bug in MAUI involving the collection views not updating their sizes when their data has changed in a nested list view.
Here is the code that I have so far:
public void OnSectionTapped(ItemObject section)
{
section.Expanded = !section.Expanded;
#if IOS
var baseView = MainCollectionView.Handler.PlatformView;
if(baseView != null)
{
var view = baseView as UIView;
if(view != null)
{
var subViewItemIsCollecitonView = view.Subviews[0] is UICollectionView;
if(subViewItemIsCollecitonView)
{
var iosCollectionView = (view.Subviews[0] as UICollectionView);
int index = section.Index;
NSObject? encodedIndex = new NSNumber(index);
//This is where the value needs
// to be encoded somehow, since this
//obviously causes a type error.
NSIndexPath iosIndex = new NSIndexPath(new NSCoder().Encode(encodedIndex));
NSIndexPath[] iosIndexSet = { iosIndex };
iosCollectionView.ReloadItems(iosIndexSet);
}
}
}
#endif
}
As you can see, I have tried converting the index int that I have set up in each of my iterable objects within my collection view to an NSNumber, but I had hit a roadblock when setting up an NSIndexPath object to be read by the ReloadItems method; the reason being that I’m not sure what to do with the NSCoder object to generate a proper NSIndexPath value to be loaded in the
corresponding NSIndexPath array below. Any help on what to do here would be great. Thanks!