F# Xamarin 中的 SizeforItematIndexPath
Posted
技术标签:
【中文标题】F# Xamarin 中的 SizeforItematIndexPath【英文标题】:SizeforItematIndexPath in F# Xamarin 【发布时间】:2018-01-18 11:58:07 【问题描述】:我正在尝试覆盖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)
但是,这会引发错误,说明没有这样的方法。我已经打开了UICollectionViewFlowLayout
的F#
实现,但是我在那里找不到这个方法:
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);
我不确定我做错了什么。
【问题讨论】:
【参考方案1】:GetSizeForItem 定义在UICollectionViewDelegateFlowLayout
您必须创建从UICollectionViewDelegateFlowLayout
派生的子类,并将其分配给CollectionView.Delegate
。
【讨论】:
以上是关于F# Xamarin 中的 SizeforItematIndexPath的主要内容,如果未能解决你的问题,请参考以下文章
F# Xamarin 中的 SizeforItematIndexPath
NSURLSession 下载任务 - Xamarin iOS F#
未调用 ItemSelected - Xamarin.iOS F#