c# - UICollectionViewCell 定义 F#

标签 c# ios xamarin f# uicollectionview

我如何将以下 C# 代码转换为 F#:

public class AnimalCell : UICollectionViewCell
{
[Export ("initWithFrame:")]
  public AnimalCell (RectangleF frame) : base (frame) {}
}

我尝试按照以下链接中的示例进行操作,但是,我不知道下一步如何进行: Overriding Constructors in F#

到目前为止我想出的是:

[<Register ("AnimalCell")>]
type AnimalCell (handle: IntPtr) as this = 
    inherit UICollectionViewCell (handle)

我应该在哪里添加 Export 以及参数?我知道我应该使用 new() 但我不确定如何继续。

最佳答案

像这样的事情会让你开始:

F# UICollectionViewCell 子类

[<Register ("AnimalCell")>]
type AnimalCell =   
    inherit UICollectionViewCell

    [<DefaultValue>] static val mutable private id : NSString
    static member init = 
        printfn "Initializing AnimalCell."
        AnimalCell.id <- new NSString("animalCell")

    [<Export("init")>]
    new() = { inherit UICollectionViewCell() } then AnimalCell.init
    [<Export("initWithFrame:")>]
    new(frame: CGRect) = { inherit UICollectionViewCell(frame) } then AnimalCell.init
    [<Export("initWithCoder:")>]
    new(coder: NSCoder) = { inherit UICollectionViewCell(coder) } then AnimalCell.init

    new(handle: IntPtr) = { inherit UICollectionViewCell(handle) } then AnimalCell.init

    override this.ReuseIdentifier = AnimalCell.id

关于c# - UICollectionViewCell 定义 F#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48038906/

相关文章:

c# - 如何在图片框控件中突出显示图像的特定部分

ios - Iphone SDK 禁用另一个应用程序的通知

c# - Xamarin.Forms iOS 的 Xamarin.Behaviors

xamarin - .Net 标准 Xamarin.Forms 应用程序在 Android 和 iOS 项目中是否具有依赖项、NuGet 和 SDK 文件夹?

c# - WPF Image using DataTrigger with Storyboard throwing 无法在不可变对象(immutable对象)实例上设置动画 '((RenderTransform).(RotateTransform.Angle)'

c# - sql server 查询真的可以被取消/杀死吗?

c# - 开始将 Redis 与 ASP.NET 结合使用

ios - 如何使用 Swift 单击按钮以编程方式将文本输入到 UITextView 中

ios - 使用 Masonry 自动布局 UITableViewCell

c# - 将 JSON 反序列化为可读格式