How can I provide an implementation of GetSizeForItem in a UICollectionViewController?

UICollectionViewDelegateFlowLayout has a sizeForItem method ( GetSizeForItem in MonoTouch).

But I do not explicitly provide the delegate - instead, I inherit from the UICollectionViewController.
It mixes the functions of the data source delegates and delegates, but does not support this method.

I tried adding this to my controller:

[Export ("collectionView:layout:sizeForItemAtIndexPath:")] public virtual SizeF GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath) { return new SizeF (100, 100); } 

and he was never called.

How can I provide this method without resorting to separating the delegate from the data source?

+7
source share
2 answers

You can not. In Obj-C, a viewcontroller (or any class) object can accept a delegate protocol. This is not possible in Monotouch. You gave a delegate instance. But it could be a private class

 public class CustomCollectionViewController:UICollectionViewController { public CustomCollectionViewController():base() { this.CollectionView.Delegate = new CustomViewDelegate(); } class CustomViewDelegate: UICollectionViewDelegateFlowLayout { public override System.Drawing.SizeF GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath) { return new System.Drawing.SizeF (100, 100); } } } 
+11
source

Edit: Without having to subclass the delegate, add this to your UICollectionviewSource

 /** Other methods such as GetItemsCount(), GetCell()... goes here **/ [Export ("collectionView:layout:sizeForItemAtIndexPath:"), CompilerGenerated] public virtual CGSize GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath) { return new CGSize (width, height); } 
+8
source

All Articles