title: Issues with protocols bindings in Xamarin.iOS
body: <p>I tried to bind a native library in iOS (Objective-C) in Xamarin.iOS.</p>
  
  <p>The header file is simple but I can't find a proper solution.</p>
  
  <p>Here is the header file:</p>
  
  <pre><code>@protocol FooFinished
  
  -(void)fooFinished:(NSString*)key;
  
  @end
  
  @protocol FooViewController
  
  @property (nonatomic, copy) void (^onClosed)();
  
  @end
  
  @interface Foo : NSObject {
  
  }
  
  + (UIViewController&lt;FooViewController&gt;*)fooViewControllerWithFinish:(id&lt;FooFinished&gt;)f;
  
  @end
  </code></pre>
  
  <p>And here is my bindings in ApiDefinition.cs : </p>
  
  <pre><code>namespace FooBindings
  {
      interface IFooFinished { }
  
      // @protocol FooFinished &lt;NSObject&gt;
      [Protocol, Model]
      [BaseType(typeof(NSObject))]
      interface FooFinished
      {
          // @required -(void)fooFinished:(NSString *)key;
          [Abstract]
          [Export("fooFinished:")]
          void FooFinishedWithKey(string key);
      }
  
      interface IFooViewController { }
  
      // @protocol FooViewController &lt;NSObject&gt;
      [Protocol, Model]
      [BaseType(typeof(NSObject))]
      interface FooViewController
      {
          // @required @property (copy, nonatomic) void (^onClosed)();
          [Abstract]
          [Export("onClosed", ArgumentSemantic.Copy)]
          Action OnClosed { get; set; }
      }
  
      // @interface Foo : NSObject
      [BaseType(typeof(NSObject))]
      interface Foo
      {
          // +(UIViewController&lt;FooViewController&gt; *)fooViewControllerWithFinish:(id&lt;FooFinished&gt;)f;
          [Static]
          [Export("fooViewControllerWithFinish:embedOptions:")]
          IFooViewController FooViewControllerWithFinish(IFooFinished f);
      }
  }
  </code></pre>
  
  <p>And in my app, I have a MainViewController. Inside, I create my FooViewController like this:</p>
  
  <pre><code>public partial class MainViewController : UIViewController, IFooFinished
      {
          private IFooViewController Foo { get; set; }
  
          protected internal MainViewController(IntPtr handle) : base(handle)
          {
          }
  
          public override void ViewDidLoad()
          {
              base.ViewDidLoad();
              // Perform any additional setup after loading the view, typically from a nib.
  
              startButton.TouchUpInside += (sender, e) =&gt;
              {
                  if (Foo == null)
                  {
                      Foo = Foo.FooViewControllerWithFinish(this);
                  }
  
                  this.PresentViewController(Foo, true, null);
              };
          }
  
          public void FooFinishedWithKey(string key)
          {
              this.DismissViewController(true, null);
          }
      }
  </code></pre>
  
  <p>My problem is: I can't use "this.PresentViewController(Foo, true, null);" because "Foo" is not a UIViewController. I tried to cast it but I have a exception that says "Invalid cast exception". </p>
  
  <p>Thank you for helping me guys.</p>
  
  <p><strong>EDIT</strong>:
  Got it working ! I made these changes in my ApiDefinition.cs:</p>
  
  <pre><code>// @interface Foo : NSObject
  [BaseType(typeof(NSObject))]
  interface Foo
  {
      // +(UIViewController&lt;FooViewController&gt; *)fooViewControllerWithFinish:(id&lt;FooFinished&gt;)f;
      [Static]
      [Export("fooViewControllerWithFinish:embedOptions:")]
      FooViewController FooViewControllerWithFinish(IFooFinished f);
  }
  
  [BaseType(typeof(NSObject))]
  [Protocol, Model]
  interface IFooViewController
  {
      // @required @property (copy, nonatomic) void (^onClosed)();
      [Abstract]
      [Export("onClosed", ArgumentSemantic.Copy)]
      Action OnClosed { get; set; }
  }
  
  // @protocol FooViewController &lt;NSObject&gt;
  [BaseType(typeof(UIViewController))]
  [Model]
  interface FooViewController : IFooViewController
  {
  
  }
  </code></pre>