Paul Knopf
Paul Knopf

Reputation: 9786

MonoTouch conformsToProtocol=False for valid protocols

I have created bindings for AQGridView. The project has a delegate and datasource protocol.

The type AQGridView exposes a GridViewDataSource and GridViewDelegate property. When setting either property with a custom class, an error get's throw from the bounded library (not the runtime). There is message is:

Argument to -setDataSource must conform to the AQGridViewDataSource protocol

This error is thrown manually by calling "conformsToProtocol" within the objective-c library.

- (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:)];
}

The delegate has no required methods, so it is easy to "conform", and for the datasource, I have implemented all the required fields. So the question is:

Why does conformsToProtocol return NO in iOS when the managed type I send it inherits from the correct type and implements the required methods (if any)?

UPDATE

I have overrided ConformsToProtocol on our c# type to get the method in the iOS type to pass.

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

I still don't think I need to do this, but it now works.

Upvotes: 1

Views: 165

Answers (1)

Rolf Bjarne Kvinge
Rolf Bjarne Kvinge

Reputation: 19345

You have done it correctly, we currently do not automatically respond to conformsToProtocol with YES for managed classes, even if they inherit from the proper bound class/protocol.

Upvotes: 1

Related Questions