在 Objective-C 中,UITableViewControllerDelegate 等委托(delegate)是协议(protocol),因此我可以在一个类中实现多个委托(delegate)。
在 Monotouch 中,所有 iOS 委托(delegate)都公开为 C# 类。这使得不可能在单个 Controller 类上实现两个委托(delegate),因为 C#(正确地,IMO)只允许单继承。
委托(delegate)声明是否作为 C# 接口(interface)存在于 Monotouch 框架的某处? (这将是我们最接近 Objective-C 的协议(protocol))
如果我需要在 Monotouch/C# 中的一个类上实现多个委托(delegate),我有什么选择?
最佳答案
您可以使用 WeakDelegate
来执行此操作,但您必须正确设置所有 Export
装饰。靠近底部的弱代表文档 here . Here是具有弱委托(delegate)的 UITableViewSource
示例。
我不确定为什么 Xamarin 必须使用类而不是 Obj-C 协议(protocol)的接口(interface),但我猜这是他们必须解决的一个限制。
关于c# - 如何在 Monotouch 中实现多个委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16266384/