F#接口实现错误

时间:2018-02-23 16:30:52

标签: c# interface f#

我正在尝试在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, e.g. 'interface ... with member ...'.

我不明白这一点,因为界面中没有其他方法。

1 个答案:

答案 0 :(得分:3)

请注意,您的ICardViewDataSource界面也会实现INativeObject。这意味着您还需要实现该接口的所有成员。在这种情况下,有一个名为Handle的属性缺失。

另外值得注意的是,它实现了IDisposable,这意味着您可能还需要Dispose方法。

相关问题