driis
driis

Reputation: 164291

How to implement multiple delegates in Monotouch?

In Objective-C, delegates such as UITableViewControllerDelegate are protocols, so I can implement multiple in one class.

In Monotouch, all the iOS delegates are exposed as C# classes. This makes it impossible to implement two delegate on a single controller class, since C# (rightly, IMO) only allows single inheritance.

Does the delegate declarations exist as C# interfaces somewhere in the Monotouch framework ? (This would be the closest we could come to the protocol from Objective-C)

What are my options if I need to implement multiple delegates on a class in Monotouch / C# ?

Upvotes: 5

Views: 1561

Answers (1)

jonathanpeppers
jonathanpeppers

Reputation: 26495

You can use WeakDelegate to do this, but you have to have all the Export decorations correct. Documentation on weak delegates near the bottom here. Here is an example of UITableViewSource with weak delegates.

I'm not sure exactly why Xamarin had to use classes instead of interfaces for Obj-C protocols, but I'm guessing it is a limitation they had to workaround.

Upvotes: 6

Related Questions