Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

PageRenderer cannot instantiate protocol class using Handle (protocol from an iOS library binding)

$
0
0

I created a binding project in Xamarin and bound an external iOS Objective C Library.

I can create an iOS project in Xamarin and consume the binding successfully where the optional OBJ-c protocol methods (callbacks) are invoked based on user action.

My Class definition in Xamarin iOS project (the code below works and when the user takes the action (method1) get called:

public partial class test_view_ControllerViewController: UIViewController, ICustomiOSBindingLibDelegate
{
    public test_view_ControllerViewController (IntPtr handle) : base (handle)
    {
    }

    //delegate method
    [Export ("method1:")]
     public   void method1 (UIView view)
    {
        Console.WriteLine("Test");
    }

    public viewDidLoad ( )
    {
            base.ViewDidLoad ();

            //this works ok with UIViewController
            MyDelegate = new MyDelegate(this.handle);

            MyViewOptions opts = new MyViewOptions();
            opts.Delegate = MyDelegate;
            MyView vw = new MyView(opts);
            //add sub view.
    }
}

Now i am trying to use this in a Xamarin.Forms project.
Here i am using Custom Renderer of type PageRenderer.

    public class test_view_ControllerViewController : PageRenderer, ICustomiOSBindingLibDelegate
    {
            //delegate method
            [Export ("method1:")]
             public   void method1 (UIView view)
            {
                Console.WriteLine("Test");
            }

            public viewDidLoad ( )
            {
                    base.ViewDidLoad ();

                    //the delegate below with this.handle IntPtr causes NO view to render.
                    //I have tried using this.ViewController.Handle, this.ClassHandle and nothing appears to work.
                    MyDelegate = new MyDelegate(this.Handle);

                    MyViewOptions opts = new MyViewOptions();
                    opts.Delegate = MyDelegate;
                    MyView vw = new MyView(opts);
                    //add sub view.
            }

    }

The problem is when i instantiate the delegate above nothing (no view)gets rendered on the screen. Its almost looks like the handle is invalid. How would i get the correct handle for this setup to work.

Thanks


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>