Monotouch 绑定无法接受委托模型 [英] Monotouch binding fails to accept delegate model

查看:22
本文介绍了Monotouch 绑定无法接受委托模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Applifier API 设置了以下绑定:

I have the following binding for the Applifier API:

namespace MonoTouch.Applifier {

[BaseType (typeof (NSObject))]
interface Applifier {
    [Export ("initWithApplifierID:withWindow:supportedOrientations:"), Static]
    Applifier InitWithApplifierId (string applifierId, UIWindow withWindow,
        UIDeviceOrientation firstOrientation, IntPtr orientationsPtr);

    [Export ("initWithApplifierID:withWindow:delegate:usingBanners:usingInterstitials:usingFeaturedGames:supportedOrientations:"), Static]
    Applifier InitWithApplifierId (string applifierId, UIWindow withWindow,
        ApplifierGameDelegate gameDelegate, bool usingBanners, bool usingInterstitials,
        bool usingFeaturedGames, UIDeviceOrientation firstOrientation, IntPtr orientationsPtr);

    [Export ("sharedInstance"), Static]
    Applifier SharedInstance { get; }

    [Wrap ("WeakDelegate")]
    ApplifierGameDelegate Delegate { get; set; }

    [Export ("gameDelegate", ArgumentSemantic.Retain)]
    NSObject WeakDelegate { get; set; }

    [Export ("prepareFeaturedGames")]
    void PrepareFeaturedGames ();

    [Export ("showFeaturedGames")]
    void ShowFeaturedGames ();

    [Export ("showBannerAt:")]
    void ShowBannerAt (PointF position);
}

[BaseType (typeof (NSObject))]
[Model]
interface ApplifierGameDelegate {
    [Export("applifierInterstitialReady"), Abstract]
    void InterstitialReady ();

    [Export("applifierFeaturedGamesReady"), Abstract]
    void FeaturedGamesReady ();

    [Export("applifierBannerReady")]
    void BannerReady ();

    [Export("applifierAnimatedReady")]
    void AnimatedReady ();

    [Export("applifierCustomInterstitialReady")]
    void CustomInterstitialReady ();

    [Export("pauseGame")]
    void PauseGame ();

    [Export("resumeGame")]
    void ResultGame ();
}
}

在我的 extras C# 文件中有两个方法可以更轻松地调用这些 init 方法.我认为它们在这里不相关,但如果需要,我可以包括它们.

There are two methods in my extras C# file that make calling those init methods a little easier. I don't think they're relevant here, but I can include them if needed.

这是gameDelegate"的 Obj-C 声明:

Here's the Obj-C declaration of "gameDelegate":

@property (nonatomic, retain) id<ApplifierGameDelegate> gameDelegate;

以及ApplifierGameDelegate的协议定义:

And the protocol definition of ApplifierGameDelegate:

@protocol ApplifierGameDelegate <NSObject>
- (void)applifierInterstitialReady;
- (void)applifierFeaturedGamesReady;
@optional
- (void)applifierBannerReady;
- (void)applifierAnimatedReady;
- (void)applifierCustomInterstitialReady;
- (void)pauseGame;
- (void)resumeGame;
@end

这里的问题是,无论我尝试什么,我都无法在我的单点触控项目中获取委托实现上的方法来从 Applifier 获取回调.一些注意事项:

The problem here is that no matter what I try, I can't get the methods on my delegate implementation in my monotouch project to get callbacks from Applifier. Some notes:

我按照 applifier 教程在 Xcode 中有一个非常简单的示例应用程序,它确实有效(测试用例是当显示特色游戏时,pauseGame"方法在委托上被调用)

I have a very simple example app in Xcode following the applifier tutorial that does work (the test case is that when the featured games are shown, the "pauseGame" method gets called on the delegate)

  • 我注意到,如果我将任何对象分配给 WeakDelegate,则不会有任何抱怨,这让我感到很惊讶.例如,没有错误或警告: Applifier.SharedInstance.WeakDelegate = new NSString("Foo");
  • 我可以从共享实例中获取委托并自己调用该方法,但它确实被调用了.例如: Applifier.SharedInstance.Delegate.PauseGame();-- 无论是将我的委托实例分配给 WeakDelegate、Delegate,还是通过接受委托作为参数之一的 init 方法,这都适用.

我现在唯一的结论是似乎有两件事是对的:

My only conclusion right now is that it seems like two things are true:

  • 我可以通过绑定将任何对象分配给 gameDelegate,没有任何抱怨
  • 某处无法识别我的 ApplifierGameDelegate 接口与 AppliferGameDelegate 协议匹配.

我注意到的唯一其他奇怪的事情是,在我在 monotouch-bindings git 项目中探索的所有其他示例绑定中,我还没有看到任何其他人在委托属性上使用保留属性.

The only other weird thing I've noticed is that in all the other example bindings I've poked around in in the monotouch-bindings git project, I haven't seen any others that use the retain property on a delegate property.

我的 monotouch-bindings 分支可以在 https://github.com/threerings/monotouch-绑定.当前的 HEAD 是一种可以完成我们需要完成的工作的混合解决方法,但我仍然希望以完全正确的绑定结束(只需要委托在 C# 领域工作).我在这个问题中写的原始绑定可以在提交 fdcff4662a36ac42fbe135c098ff7f71cbdf205d 处查看.

My fork of monotouch-bindings can be found at https://github.com/threerings/monotouch-bindings. The current HEAD is a hacked together workaround that gets what we need done, but I'd still like to end up with a full proper binding (just need the delegate to work from C# land). The original binding that I was writing about in this question can be viewed at commit fdcff4662a36ac42fbe135c098ff7f71cbdf205d.

推荐答案

我根据你写的绑定,请检查这个绑定是否适合你,我没有测试它们,因为我没有 ApplifierID

I wrote bindings based on yours, please check if this bindings works for you, I have not tested them since I don't have an ApplifierID

https://github.com/dalexsoto/AlexTouch.Applifier

我向 Delegate 类添加了事件,以便于使用并绑定了大部分 API.

I added events to Delegate class for an easier usage and bound most of the API.

希望能帮到你

亚历克斯

这篇关于Monotouch 绑定无法接受委托模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆