I have a UIViewController
that has a UICollectionView
added as a subview in the viewDidLoad. I am using a UICollectionViewFlowLayout
and have created a custom MvxCollectionViewSource
to manage the cells.
I provide the cell information in the constructor of the layout object which does not make it flexible for device and orientation changes.
UICollectionViewLayout layout = new UICollectionViewFlowLayout () {ItemSize = new SizeF (354, 150),
ScrollDirection = UICollectionViewScrollDirection.Vertical
};
Allocating my UICollectionView in the ViewDidLoad method.
CollectionView = new UICollectionView (this.View.Bounds, layout);
CollectionView.Delegate = new CustomViewDelegate();
CollectionView.RegisterClassForCell (typeof(ProjectCollectionCell), ProjectCollectionCell.Key);
CollectionView.Source = new ProjectCollectionSource (CollectionView, this,ProjectCollectionCell.Key);
CollectionView.BackgroundColor = UIColor.Clear;
// CollectionView.RegisterClassForSupplementaryView (typeof(Header), UICollectionElementKindSection.Header, headerId);
CollectionView.AllowsMultipleSelection = true;
this.View.AddSubview (CollectionView);
Now the ProjectCollectionSource is my custom source and have created a UICollectionViewDelegateFlowLayout
as mentioned here.
The UICollectionViewDelegateFlowLayout
is as below but it never gets called.
class CustomViewDelegate: UICollectionViewDelegateFlowLayout
{
public override CoreGraphics.CGSize GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
{
return new CoreGraphics.CGSize (100, 100);
}
}