Xamarin access to iOS binding QualtricsSurveyViewController

Viewed 82

I have created a bindings library for iOS, generated an APIDefintions & StructsAndEnums class using sharpie bind, added a native reference to the bindings library, set the framework properties accordingly, and added a native reference of the bindings library to the iOS proj.

In the AppDelegate class, I am trying to initialize the ViewController, but the app crashes with the message:

Fatal error: Use of unimplemented initializer 'init(nibName:bundle:)' for class 'Qualtrics.QualtricsSurveyViewController'

Here is my VC code:

public partial class QualtricsViewController : QualtricsSurveyViewController
{
    public QualtricsViewController(NSString nibNameOrNil, NSNumber bundle) : base(nibNameOrNil, bundle)
    {
        this.Init();
    }
    public QualtricsViewController(NSCoder coder) : base(coder)
    {
        base.Init();
    }
    public QualtricsViewController()
    {

    }
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        var btn = UIButton.FromType(UIButtonType.System);
        btn.Frame = new CGRect(20, 200, 280, 44);
        btn.SetTitle("Click Me", UIControlState.Normal);

        var user = new UIViewController();

        btn.TouchUpInside += (sender, e) => {
            this.NavigationController.PushViewController(user, true);
        };
    }
}

Within the AppDelegate class I am calling it like this:

 var qualtricsVC = new QualtricsViewController(); 

I am relatively new to setting up Native Bindings. My Native Binding proj compiles correctly and everything seems to be fine, until I call the QualtricsSurveyViewController. Any help would be appreciated. Thanks in advance!

1 Answers

The error indicates that you're doing incorrect initializing with the viewcontroller.

Notice : if you create the class constuctor public QualtricsViewController(nibNameOrNil, bundle) for the viewcontroller , it means the viewcontroller must come from Storyboard, and we can't initialize it programatically.

To solve the problem ,removing the constuctor should works.

public partial class QualtricsViewController : QualtricsSurveyViewController
{
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        var btn = UIButton.FromType(UIButtonType.System);
        btn.Frame = new CGRect(20, 200, 280, 44);
        btn.SetTitle("Click Me", UIControlState.Normal);

        var user = new UIViewController();

        btn.TouchUpInside += (sender, e) => {
            this.NavigationController.PushViewController(user, true);
        };
    }
}
Related