Daniil Popov
Daniil Popov

Reputation: 471

Bind Objective-C code to C# (Monotouch). Multiple protocol inheritance

I am beginner with Objective-C. So I write my app using C# + Monotouch. Now I need to use third-party library TTTAttributedLabel written in ObjC. It is neccessary to bind it's code to C#. There is some interesting construction:

@protocol TTTAttributedLabel <NSObject>
@property (nonatomic, copy) id text;
@end

@interface TTTAttributedLabel : UILabel <TTTAttributedLabel, UIGestureRecognizerDelegate>
/* some code here */
@end

It is clear to me about TTTAttributedLabel and UILabel inheritance. I did it this way:

[BaseType (typeof (NSObject))]
interface TTTAttributedLabel{
     // code here
}

[BaseType (typeof (UILabel))]
interface UITextField : TTTAttributedLabel{
}

But I don't know how to inherite UIGestureRecognizerDelegate, because in Objective-C it is a protocol but in Monotouch it is a class. So I can not inherite interface from class.

What is the correct way to do this?

Upvotes: 0

Views: 462

Answers (1)

miguel.de.icaza
miguel.de.icaza

Reputation: 32694

In this case, what the UIGestureRecognizerDelegate means is that the object will conform to the protocol, and as you noticed, we mapped protocols to classes which prevents this from working.

But at the core what this does is allow instance sof TTTAttributedLabel to be passed to a UIGestureRecognizer's Delegate property.

For these cases, you can instead use the WeakDelegate, which will not perform C#-level type checking and allow you to assign the instance of TTTAttributedLabel to a UIGestureRecognizer.WeakDelegate property.

Upvotes: 1

Related Questions