【问题标题】:Monotouch binding fails to accept delegate modelMonotouch 绑定无法接受委托模型
【发布时间】:2012-10-26 04:46:09
【问题描述】:

我对 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# 文件中有两种方法可以更轻松地调用这些初始化方法。我认为它们在这里不相关,但如果需要,我可以将它们包括在内。

这是“gameDelegate”的 Obj-C 声明:

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

以及ApplifierGameDelegate的协议定义:

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

这里的问题是,无论我尝试什么,我都无法在我的 monotouch 项目中获取委托实现的方法来获取来自 Applifier 的回调。一些注意事项:

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

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

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

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

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

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

【问题讨论】:

  • 你能提供标题吗?如果你想通过 g mail 给我发邮件给 dalexsoto,我可以查看你的绑定
  • 我订阅了 Applifier 但我的帐户仍在审核中...
  • 除了那里的两个声明之外你还需要什么?
  • 意识到我可以做得更好。这是我的 monotouch-bindings 分支:github.com/threerings/monotouch-bindings。如果您在 Applifier/binding 中制作,它也会为您获取 applifier 项目,因此您将拥有我所拥有的一切。你需要一个 applifier app id 来测试它,但至少所有代码都在那里。
  • 对不起,我花了很长时间才回答,但我有很多忙碌的日子

标签: ios xamarin.ios


【解决方案1】:

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

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

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

希望对你有帮助

亚历克斯

【讨论】:

  • 有机会尝试一下。不幸的是,它的结果与我编写的绑定相同。委托以完全相同的方式被忽略。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-11
  • 1970-01-01
  • 1970-01-01
  • 2020-12-04
  • 2023-03-14
  • 1970-01-01
相关资源
最近更新 更多