【问题标题】:Unrecognised selector when calling binding method调用绑定方法时无法识别的选择器
【发布时间】:2014-11-22 09:34:06
【问题描述】:

我正在尝试将我创建的基本 Objective-C 库绑定到 Xamarin 项目。 .h 文件是:

#import <Foundation/Foundation.h>
@import UIKit;

@interface StarIOFunctions : NSObject {

}

+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image;

@end

我尝试使用以下 ApiDefinition 创建绑定:

using System;
using System.Drawing;

using MonoTouch.ObjCRuntime;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace BindingTake2
{
    [BaseType (typeof (NSObject))]
    interface StarIOFunctions {
        [Export ("GetDataToSendToPrinter:image")]
        NSMutableData GetDataToSendToPrinter (UIImage image);
    }
}

一切都可以编译,但是当我在我的应用程序中运行它时:

UIImage image = UIImage.FromBundle("image1.png");
StarIOFunctions functions = new StarIOFunctions ();
var output = functions.GetDataToSendToPrinter (image);

我的应用程序崩溃并出现以下错误:

Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[StarIOFunctions GetDataToSendToPrinter:image]: unrecognized selector sent to instance 0x7cdb50f0

现在,我认为这与我发送图像有关,而不是指向图像的指针 - 但我完全迷路了,无法弄清楚我到底做错了什么。

【问题讨论】:

    标签: c# ios binding xamarin.ios xamarin


    【解决方案1】:

    您似乎在选择器名称中包含参数名称,即

    [Export ("GetDataToSendToPrinter:image")]
    

    应该是:

    [Export ("GetDataToSendToPrinter:")]
    

    最后一列 ':' 表示需要一个参数 - 但您不需要命名它(在选择器中),因为前面的字符串应该暗示它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多