xamarin.ios – 如何在UICollectionViewController中提供GetSizeForItem实现?

前端之家收集整理的这篇文章主要介绍了xamarin.ios – 如何在UICollectionViewController中提供GetSizeForItem实现?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
UICollectionViewDelegateFlowLayout有一个名为 sizeForItem方法(MonoTouch中的 GetSizeForItem).

但我没有明确地提供委托 – 相反,我继承自UICollectionViewController.
它混合了数据源和委托功能,但没有这种方法来覆盖.

我尝试将其添加到我的控制器:

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

它从未被称为.

如何在不诉诸分离委托和数据源的情况下提供此方法

解决方法

你不能.在Obj-C中,viewcontroller(或任何类)对象可以采用委托协议.这在Monotouch中是不可能的.您给了使用委托实例.但这可以是私人课程
  1. public class CustomCollectionViewController:UICollectionViewController
  2. {
  3. public CustomCollectionViewController():base()
  4. {
  5.  
  6. this.CollectionView.Delegate = new CustomViewDelegate();
  7.  
  8. }
  9.  
  10. class CustomViewDelegate: UICollectionViewDelegateFlowLayout
  11. {
  12.  
  13. public override System.Drawing.SizeF GetSizeForItem (UICollectionView collectionView,NSIndexPath indexPath)
  14. {
  15. return new System.Drawing.SizeF (100,100);
  16. }
  17. }
  18. }

猜你在找的iOS相关文章