簡體   English   中英

F#接口實現錯誤

[英]F# Interface Implementation Error

我正在嘗試在F#中實現以下接口:

using Foundation;
using ObjCRuntime;
using System;
using System.Runtime.CompilerServices;
using UIKit;

namespace Softweb.Xamarin.Controls.iOS
{
    [Protocol (Name = "ZLSwipeableViewDataSource", WrapperType = typeof(CardViewDataSourceWrapper))]
    public interface ICardViewDataSource : INativeObject, IDisposable
    {
        //
        // Methods
        //
        [Export ("nextViewForSwipeableView:"), Preserve (Conditional = true), CompilerGenerated]
        UIView NextCardForCardView (CardView cardView);
    }
}

為此,我有以下代碼:

[<Register ("BackgroundAnimationViewControllerDataSource")>]
type BackgroundAnimationViewControllerDataSource () =
    interface ICardViewDataSource with 
         member this.NextCardForCardView(cardView : CardView) = 
            let card = new UIView()
            card.Frame <- CGRect()
            card.BackgroundColor <- UIColor.Blue
            card.Layer.ShouldRasterize <- true
            card 

但這給了我錯誤:

No implementation was given for 'ObjCRuntime.INativeObject.get_Handle() : nativeint'. Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, eg 'interface ... with member ...'.

我不明白這一點,因為界面中沒有其他方法。

請注意,您的ICardViewDataSource接口還實現了INativeObject 這意味着您也需要實現該接口的所有成員。 在這種情況下,缺少名為Handle的屬性。

同樣值得注意的是,它實現了IDisposable ,這意味着您可能還需要使用Dispose方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM