2013-03-20 23 views
0

我試圖將TapForTap iOS SDK移植到我的Monotouch C#應用程序中。在Xamarin中綁定iOS代理時出錯

使用文檔和綁定發生器我創建了以下結合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(); 

      [...] 
} 
} 

在我的項目,我創建了一個類TapForTapDelegate實施TapForTapAdViewDelegate。

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;)

回答

2

問題是,init *方法綁定爲C#構造函數。

試試這個:

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

    ... 
} 

Here是如何結合的Objective-C庫中Xamarin.iOS更多的文檔。特別參見3.3 Binding Constructors

+0

謝謝!這就是訣竅! – 2013-03-22 13:52:56