Kar*_*sen 5 binding objective-c xamarin.ios xamarin-studio
这是我关于将objective-c库绑定到xamarin项目的最后一个问题的后续内容.所以我想我将自己创建api定义,但我无法弄清楚如何将Objective-c委托重写为C#delegates/events.我已经明白,Objective-c委托与C#委托不同,但更像是C#事件.
这是objective-c委托定义(来自头文件):
@protocol LineaDelegate
@optional
-(void)connectionState:(int)state;
@end
Run Code Online (Sandbox Code Playgroud)
这是objective-c类定义(来自头文件):
@interface Linea : NSObject
-(void)connect;
@end
Run Code Online (Sandbox Code Playgroud)
connect方法在后台工作,并通过connectionState委托通知调用者连接成功.
现在,我如何正确绑定api?到目前为止,这是我的ApiDefinition.cs:
[BaseType(typeof(NSObject))]
interface Linea{
[Export ("isPresent")]
bool IsPresent();
//the delegate that will be notified of Linea events
[Export("addDelegate:")]
void AddDelegate (NSObject newDelegate);
[Export("connect")]
void Connect ();
}
Run Code Online (Sandbox Code Playgroud)
如何将objective-c委托转换为Xamarin工作室和C#中有用的东西?
现在,当我在这里发布问题时,我自己就找到了解决方案......我在这里发布解决方案不仅供我自己参考,也供其他遇到同样问题的人参考。
我找到了这个教程(参见第 4.3 章)并认为我必须使用弱委托。像魅力一样工作!
| 归档时间: |
|
| 查看次数: |
2411 次 |
| 最近记录: |