0

我正在尝试将 TapForTap iOS SDK 移植到我的 Monotouch C# 应用程序。

使用文档和绑定生成器,我创建了以下绑定 ApiDefintion:

namespace TapForTap {

[BaseType (typeof (NSObject))]
interface TapForTap {
    [...]
    [Static]
    [Export ("initializeWithAPIKey:")]
    void InitializeWithAPIKey (string key);
}

[BaseType (typeof (NSObject))]
[Model]
interface TapForTapAdViewDelegate {
    [Abstract]
    [Export ("rootViewController")]
    UIViewController RootViewController ();

    [...]
}

[BaseType (typeof (UIView))]
interface TapForTapAdView {
    [Static]
    [Export ("initWithFrame:delegate:")]
    NSObject Init (RectangleF frame, TapForTapAdViewDelegate d);

    [Export ("loadAds")]
    void LoadAds ();

    [Export ("stopLoadingAds")]
    void StopLoadingAds ();

            [...]
}
}

在我的项目中,我创建了一个实现 TapForTapAdViewDelegate 的类 TapForTapDelegate。

public partial class TapForTapAdDelegate : TapForTapAdViewDelegate {
    public override UIViewController RootViewController () {
        return Application.mainViewController;
    }

    [...]
}

问题是我真的不确定我是否正确实现了 initWithFrame:delegate: 函数。

每当我尝试使用以下代码时,我都会得到NSInvalidArgumentException Reason: +[TapForTapAdView initWithFrame:delegate:]: unrecognized selector sent to class 0x36dac4

bannerAd = (TapForTapAdView) TapForTapAdView.Init (new System.Drawing.RectangleF(0, y, 320, 50), new TapForTapAdDelegate());

我究竟做错了什么?我已经尝试了几个小时,但没有找到任何解决方案。我习惯了 Java,而不是 C# 和 Objective-C ;)

4

1 回答 1

2

问题是 init* 方法被绑定为 C# 构造函数。

试试这个:

[BaseType (typeof (UIView))]
interface TapForTapAdView {
    [Export ("initWithFrame:delegate:")]
    IntPtr Constructor (RectangleF frame, TapForTapAdViewDelegate d);

    ...
}

是有关如何在 Xamarin.iOS 中绑定 Objective-C 库的更多文档。特别是参见第3.3 节绑定构造函数

于 2013-03-21T23:17:32.777 回答