覆盖方法 `GetSizeForItem` returns "no suitable method found to override"

Override method `GetSizeForItem` returns "no suitable method found to override"

我是 Xamarin iOS 开发的新手,我已经开始学习包括自定义单元格高度的 CollectionView 教程。

我想根据单元格的内容更改单元格的高度(例如,单元格是否包含标题)。 我尝试开发我的自定义 UICollectionViewFlowLayout class 如下。

public class TaskFlowLayoutDelegate : UICollectionViewFlowLayout
{
    public TaskFlowLayoutDelegate()
    {
    }

    public override CoreGraphics.CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
    {
        return new CoreGraphics.CGSize((float)UIScreen.MainScreen.Bounds.Size.Width, 100)
    }
}

但是,Xamarin IDE returns no suitable method found to override 在上面的 GetSizeForItem 函数中。

如何解决?

不确定您使用的是错误的子类还是错误的 method/property:

UICollectionViewDelegateFlowLayout 有一个带有您尝试使用的签名的 GetSizeForItem 方法。

UICollectionViewFlowLayout 有一个 ItemSize 属性.