gpt4 book ai didi

c# - 了解 MonoTouch 绑定(bind)中的 Objective C 委托(delegate)

转载 作者:行者123 更新时间:2023-11-29 13:40:20 25 4
gpt4 key购买 nike

在我想尝试一下@为 native 库创建绑定(bind)之前,我没有使用过 Objective C。

原生库有一个接受 7 个参数的 Ctor

  bob = [[Bob alloc] initWithFirstName:@"bob" 
lastName:@"barker"
zipCode:@"123456"
userId:@"123456"
viewController:vc
debug:YES
delegate:self];

我已经创建了绑定(bind)项目,其中包括 Bob 类和 BobDelegate

不幸的是,此时我被难住了......我真的不明白 delegate:self 是如何工作的,或者我将如何在 Ctor 中传递它。

在我看来,Delegates 在 C# 中的工作方式大不相同,我什至不知所措。

最佳答案

您现在可以将委托(delegate)视为 C# 接口(interface)。您会发现它们是不同的,但除其他外,它们被用作实现之间的“契约”。

我们创建了一个示例,可帮助用户了解使用 btouch 将 native obj-C 组件绑定(bind)到 C# 的常见模式。以及在项目 Makefile 中构建库的一些非常好的工作流程。您可以在此处查看 BindingSample 项目:

https://github.com/xamarin/monotouch-samples/tree/master/BindingSample

关于c# - 了解 MonoTouch 绑定(bind)中的 Objective C 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9369897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com