如何在 UICollectionViewController 中提供 GetSizeForItem 实现? [英] How can I provide GetSizeForItem implementation in UICollectionViewController?

查看:30
本文介绍了如何在 UICollectionViewController 中提供 GetSizeForItem 实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UICollectionViewDelegateFlowLayout 有一个名为 sizeForItem (GetSizeForItem 在 MonoTouch 中).

UICollectionViewDelegateFlowLayout has a method called sizeForItem (GetSizeForItem in MonoTouch).

但我没有明确提供委托,而是从 UICollectionViewController 继承.
它混合了数据源和委托功能,但没有覆盖此方法.

But I'm not providing the delegate explicitly—instead, I'm inheriting from UICollectionViewController.
It mixes data source ands delegate functionality but doesn't have this method to override.

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

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);
}

它从未被调用过.

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

How do I provide this method without resorting to separating delegate and data source?

推荐答案

你不能.在 Obj-C 中,视图控制器(或任何类)对象可以采用委托协议.这在 Monotouch 中是不可能的.你给了使用委托实例.但这可以是私人课程

You can't. In Obj-C the viewcontroller (or any class) object can adopt the delegate protocol. This is not posible in Monotouch. You gave to use a delegate instance. But this can 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);
        }
    }
}

这篇关于如何在 UICollectionViewController 中提供 GetSizeForItem 实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆