2012-12-04 40 views
1

我是Monotouch的新手。最近,我正在研究一个Monotouch绑定项目,该项目绑定了一个将自己开发为.NET框架库的自定义iOS框架。我按照Xamarin的说明,但目前我遇到了无法解决的问题。这是我的代码。Monotouch绑定 - “不能从源类型转换为目标类型。”

**HEADER FILE IN OBJECTIVE C** 

*GRG.h* 
@interface GRG: NSObject {} 

// Shared instance 
+ (GRG*) sharedG; 

// Preference class 
@property (nonatomic, readonly) GRGPreferences *preferences; 

// Driver version 
@property (readonly,copy) NSString* driverVersion; 

// More parameters... 
@end 

*GRGPreferences.h* 
@interface GRGPreferences : NSObject <GRGPreferencesProtocol>{} 

// Enable DEBUG 
@property BOOL debugEnabled; 

// More parameters... 
@end 

*GRGPreferencesProtocol.h* 
@protocol GRGPreferencesProtocol <NSObject> 

// More parameters... 
@end 

将我的头文件到这个

**API DEFINITION** 

[BaseType (typeof (NSObject))] 
interface GRG 
{ 
     [Static][Export("sharedG")] 
     GRG SharedG{ get; } 

     [Export("preferences")] 
     GRGPreferences Preferences{ get;} 

     [Export("driverVersion", ArgumentSemantic.Copy)] 
     string DriverVersion {get;} 
} 

[BaseType (typeof (GRGPreferencesProtocol))] 
public interface GRGPreferences 
{ 
     [Export("debugEnabled")] 
     bool DebugEnabled{ get; set;} 
} 

[BaseType(typeof (NSObject))] 
[Model] 
public interface GRGPreferencesProtocol 
{} 

在那之后,我创建了单一个测试应用程序测试新创建的库并访问我创造的价值。但是,我得到了一个错误。

Console.WriteLine(GRG.sharedG.DriverVersion); - 这工作正常。它返回适当的值。

GRGPreferences pref = GRG.SharedG.Preferences; - 错误:“无法从源类型转换为目标类型”。

Console.WriteLine(GRG.sharedG.Preferences.DebugEnabled); - 错误:“无法从源类型转换为目标类型”。

任何人都可以帮我吗?

+0

你有没有找到解决这个问题的方法?我有一个非常类似的问题(http://stackoverflow.com/questions/16906955/binding-a-return-type-that-c​​onforms-to-a-protocol) –

回答

1

从快看,我认为这是你想要的东西:在实现您想要的协议

[BaseType (typeof (NSObject))] 
public interface GRGPreferences : GRGPreferencesProtocol { 

GRGPreferences类型从NSObject继承。

+0

谢谢你的回应。不幸的是它不起作用。我删除了GRGPrefencesProtocol之间的链接,因此GRGPreferences只是一个NSObject,但它仍然不起作用。你有什么其他的建议? –

+0

请更新您的原始问题与您的最新消息/定义,我会再看看。 – poupou

+0

你好poupou我只是更新我的代码下面可以请你看看? –

相关问题