c# - MonoTouch conformsToProtocol=False 对于有效协议(protocol)

标签 c# ios binding xamarin.ios

我创建了 bindings for AQGridView .该项目有一个委托(delegate)和数据源协议(protocol)。

AQGridView 类型公开了一个GridViewDataSourceGridViewDelegate 属性。使用自定义类设置任一属性时,会从有界库(而非运行时)中抛出错误。有留言是:

Argument to -setDataSource must conform to the AQGridViewDataSource protocol

此错误是通过在 objective-c 库中调用“conformsToProtocol”手动抛出的。

- (void) setDataSource: (id<AQGridViewDataSource>) obj
{
    if ((obj != nil) && ([obj conformsToProtocol: @protocol(AQGridViewDataSource)] == NO ))
        [NSException raise: NSInvalidArgumentException format: @"Argument to -setDataSource must conform to the AQGridViewDataSource protocol"];

    _dataSource = obj;

    _flags.dataSourceGridCellSize = [obj respondsToSelector: @selector(portraitGridCellSizeForGridView:)];
}

委托(delegate)没有必须的方法,所以很容易“符合”,而对于数据源,我已经实现了所有的必填字段。所以问题是:

为什么当我发送的托管类型继承自正确的类型并实现所需的方法(如果有)时,conformsToProtocol 在 iOS 中返回 NO?

更新

我已经在我们的 c# 类型上覆盖了 ConformsToProtocol 以获取要传递的 iOS 类型中的方法。

public override bool ConformsToProtocol (IntPtr protocol)
{
    return true;
}

我仍然认为我不需要这样做,但现在可以了。

最佳答案

您做对了,对于托管类,我们目前不会自动使用 YES 响应 conformsToProtocol,即使它们继承自正确的绑定(bind)类/协议(protocol)也是如此。

关于c# - MonoTouch conformsToProtocol=False 对于有效协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17305139/

相关文章:

c# - 绑定(bind)不适用于自定义用户控件的依赖属性

c# - 从 SQL Server 中使用 xp_cmdshell 调用 Outlook COM 库

c# - 如何从列表中选择动态列

c# - 从一个队列中删除存在于另一个队列中的元素

ios - 使用 alamofire 下载文件获取代码 -1001

java - 数据绑定(bind) - ActivityMainBinding.java 错误 : too many parameters

c# - MSMQ 的主要优势

java - 以编程方式在 AWS S3 上启用版本控制

ios - 我如何在没有 GeoFire 的情况下查询 Firebase 地理位置,以便根据两点之间的距离返回结果?

c# - 绑定(bind)到静态属性的一种方法失败