Hi all, a friend on IRC is having this issue...
There is an abstract ViewController class called "ImageViewController" that inherit from UIViewController. It's a base class that contain some common data, let's call it X.
abstract class ImageViewController : UIViewController {
public X { get; set; }
public ImageViewController(int x)
{
this.X = x;
}
}
And then there are several UIViewControllers in the app that use it:
class FooController : ImageViewController {
Layout layout;
public FooController(int x, Layout data) : base(x)
{
layout = data;
}
public override ViewDidLoad()
{
Console.WriteLine( X );
Console.WriteLine( layout.Height ); // <- boom
}
}
And this is all implemented like this:
new FooController(20, new Layout() { Height = 30 })
But this does not work, because this will run
ImageViewController.Constructor(x)
FooController.ViewDidLoad()
FooController.Constructor(x, data)
And the app will crash with a null reference exception in ViewDidLoad. In objc land it might makes sense that after the base constructor is run the ViewDidLoad fires. But how can you pass data into the constructor then in a scenario like this so that it's available in ViewDidLoad? Or is there some other magic way this should be written?