What is the correct way to use delegation pattern in Xamarin?
in API Definitions (generated by sharpie
) I have protocol mapped to Interface
SomeDelegate:
// @protocol SomeDelegate <NSObject>
[Protocol, Model]
[BaseType (typeof(NSObject))]
interface SomeDelegate
{
// @required -(void)someMethod;
[Abstract]
[Export ("someMethod")]
void SomeMethod;
...
I have declared view controller like this:
public partial class ViewController : UIViewController
but I can't make view controller to implement my protocol like this:(can't have multiple base classes)
public partial class ViewController : UIViewController, SomeDelegate
I can implement this delegate
on some extra class:
public ViewControllerDelegate : SomeDelegate
and use this class as a delegate, but this not really convenient way for me.
I've found recently that by adding "I":
public partial class ViewController : UIViewController, ISomeDelegate
I avoid having "multiple base classes error" by (I assume) explicitly saying compiler that this is interface (protocol) not a base class.
Now I need to pass delegate as a parameter of method, and have compile error - can't convert SomeDelegate
type to SomeDelegate
Is there a way to implement delegates
in some classes like UIViewController
(whatever) ?