开发者

Why do I need to override optional ObjC methods in managed wrapper Delegate object?

Here is the scenario:

I have successfully bound two objects from a native ObjC library with the btouch tool. The bound objects are a class and a protocol that acts as its Delegate object. The Delegate object contains both required and optional methods. I have included the extra enumerations that it needs to work. Everything compiles and works perfectly, except for the fact that if I do not override some of the optional methods in the managed Delegate class, I get a You_Should_Not_Call_base_In_This_Method exception.

This is how I have created the API definition for the protocol (dummy method names):

[BaseType(typeof(NSObject))]
[Model]
interface TheDelegate
{
    #region Required
    [Abstract]
    [Export("requiredMethod:")]
    void RequiredMethod(string par);
    #endregion Required

    #region Optional
    [Export("optMethod:")]
    void OptMethod(string par);
    #endregion Optional
}

If I leave the OptMethod out of the definition, the app executes perfectly. But in that case, the method will not be available to override when I will need it and I will have to create a new assembly with btouch to include it.

So when I inherit the Delegate object like this:

private class MyDelegate : TheDelegate
{
    public override void RequiredMethod(string par)
    {
        //inside RequiredMethod override
    }
}

I get the

...base_In_This_Method

exception inside the OptMethod method. But if I inherit it with the same exact way, but the API defini开发者_开发知识库tion does not contain the OptMethod, everything works fine.

Any ideas?


This was a bug in the MonoTouch runtime that we resolved this week. It will be fixed in the next alpha release of MonoTouch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜