Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you programatically instantiate a subclassed ViewController in MonoTouch?

Tags:

xamarin.ios

I have subclassed a ViewController that was created via XCode Interface Builder. my subclass is defined like so

public MyViewControllerGeneric<T> : MyViewController{
    public MyViewControllerGeneric(IntPtr handle) : base(handle){}
}

I can use Storyboard.InstantiateViewController("MyViewController") to get an instance of MyViewController. However how do I create an instance of MyViewControllerGeneric and pass a handle to it?

Tried

var vc = new MyViewControllerGeneric<MyType>(this.Handle)
var vc = new MyViewControllerGeneric<MyType>(new IntPtr(DateTime.Now.Ticks)

both throw a SigAbort

Any Help highly appreciated.

like image 504
rams Avatar asked May 19 '26 10:05

rams


1 Answers

The IntPtr handle is not something you should be passing in.

Use this constructor instead:

public MyViewControllerGeneric<T> : MyViewController{
    public MyViewControllerGeneric() : base(){ }
}

Or this if you need a NIB loaded, depending on your base class:

public MyViewControllerGeneric<T> : MyViewController{
    public MyViewControllerGeneric() : base("MyViewControllerGeneric", null){ }
}
like image 198
jonathanpeppers Avatar answered May 22 '26 10:05

jonathanpeppers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!