我试图覆盖UICollectionViewFlowLayout
的以下方法,以指定UICollectionViewCell
的大小:
[MonoTouch.Foundation.Export("collectionView:layout:sizeForItemAtIndexPath:")]
public virtual SizeF GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
为此,我执行以下操作:
type CollectionViewFlowDelegate (handle:IntPtr) as this =
inherit UICollectionViewFlowLayout (handle)
override this.GetSizeForItem(collectionView : UICollectionView, layout : UICollectionViewLayout, indexPath : NSIndexPath) =
CGSize(100.0, 300.0)
但是,这会抛出错误,说没有这样的方法。我已经打开F#
UICollectionViewFlowLayout
的{{1}}实现,但我找不到这种方法:
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace UIKit
{
[Register ("UICollectionViewFlowLayout", true), Introduced (PlatformName.iOS, 6, 0, PlatformArchitecture.None, null)]
public class UICollectionViewFlowLayout : UICollectionViewLayout
{
//
// Static Properties
//
[Field ("UICollectionViewFlowLayoutAutomaticSize", "UIKit"), Introduced (PlatformName.iOS, 10, 0, PlatformArchitecture.None, null), Introduced (PlatformName.TvOS, 10, 0, PlatformArchitecture.None, null)]
public static CGSize AutomaticSize {
[Introduced (PlatformName.iOS, 10, 0, PlatformArchitecture.None, null), Introduced (PlatformName.TvOS, 10, 0, PlatformArchitecture.None, null)]
get;
}
//
// Properties
//
public override IntPtr ClassHandle {
get;
}
[Introduced (PlatformName.iOS, 8, 0, PlatformArchitecture.None, null), CompilerGenerated]
public virtual CGSize EstimatedItemSize {
[Export ("estimatedItemSize"), Introduced (PlatformName.iOS, 8, 0, PlatformArchitecture.None, null)]
get;
[Export ("setEstimatedItemSize:"), Introduced (PlatformName.iOS, 8, 0, PlatformArchitecture.None, null)]
set;
}
[CompilerGenerated]
public virtual CGSize FooterReferenceSize {
[Export ("footerReferenceSize")]
get;
[Export ("setFooterReferenceSize:")]
set;
}
[CompilerGenerated]
public virtual CGSize HeaderReferenceSize {
[Export ("headerReferenceSize")]
get;
[Export ("setHeaderReferenceSize:")]
set;
}
[CompilerGenerated]
public virtual CGSize ItemSize {
[Export ("itemSize")]
get;
[Export ("setItemSize:")]
set;
}
[CompilerGenerated]
public virtual nfloat MinimumInteritemSpacing {
[Export ("minimumInteritemSpacing")]
get;
[Export ("setMinimumInteritemSpacing:")]
set;
}
[CompilerGenerated]
public virtual nfloat MinimumLineSpacing {
[Export ("minimumLineSpacing")]
get;
[Export ("setMinimumLineSpacing:")]
set;
}
[CompilerGenerated]
public virtual UICollectionViewScrollDirection ScrollDirection {
[Export ("scrollDirection")]
get;
[Export ("setScrollDirection:")]
set;
}
[Introduced (PlatformName.iOS, 9, 0, PlatformArchitecture.None, null), CompilerGenerated]
public virtual bool SectionFootersPinToVisibleBounds {
[Export ("sectionFootersPinToVisibleBounds"), Introduced (PlatformName.iOS, 9, 0, PlatformArchitecture.None, null)]
get;
[Export ("setSectionFootersPinToVisibleBounds:"), Introduced (PlatformName.iOS, 9, 0, PlatformArchitecture.None, null)]
set;
}
[Introduced (PlatformName.iOS, 9, 0, PlatformArchitecture.None, null), CompilerGenerated]
public virtual bool SectionHeadersPinToVisibleBounds {
[Export ("sectionHeadersPinToVisibleBounds"), Introduced (PlatformName.iOS, 9, 0, PlatformArchitecture.None, null)]
get;
[Export ("setSectionHeadersPinToVisibleBounds:"), Introduced (PlatformName.iOS, 9, 0, PlatformArchitecture.None, null)]
set;
}
[CompilerGenerated]
public virtual UIEdgeInsets SectionInset {
[Export ("sectionInset")]
get;
[Export ("setSectionInset:")]
set;
}
[Introduced (PlatformName.iOS, 11, 0, PlatformArchitecture.None, null), Introduced (PlatformName.TvOS, 11, 0, PlatformArchitecture.None, null), Unavailable (PlatformName.WatchOS, PlatformArchitecture.All, null), CompilerGenerated]
public virtual UICollectionViewFlowLayoutSectionInsetReference SectionInsetReference {
[Export ("sectionInsetReference", ArgumentSemantic.Assign), Introduced (PlatformName.iOS, 11, 0, PlatformArchitecture.None, null), Introduced (PlatformName.TvOS, 11, 0, PlatformArchitecture.None, null), Unavailable (PlatformName.WatchOS, PlatformArchitecture.All, null)]
get;
[Export ("setSectionInsetReference:", ArgumentSemantic.Assign), Introduced (PlatformName.iOS, 11, 0, PlatformArchitecture.None, null), Introduced (PlatformName.TvOS, 11, 0, PlatformArchitecture.None, null), Unavailable (PlatformName.WatchOS, PlatformArchitecture.All, null)]
set;
}
//
// Constructors
//
[Export ("init"), EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated]
public UICollectionViewFlowLayout ();
[Export ("initWithCoder:"), DesignatedInitializer, EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated]
public UICollectionViewFlowLayout (NSCoder coder);
[EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated]
protected UICollectionViewFlowLayout (NSObjectFlag t);
}
}
我不确定我做错了什么。
答案 0 :(得分:0)
GetSizeForItem在UICollectionViewDelegateFlowLayout
您必须从UICollectionViewDelegateFlowLayout
创建子类派生,并将其分配给CollectionView.Delegate
。