Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin iOS Controller Custom Inheritance Issues with Dependency Injection

I'm having a glitch with a controller that inherits from a base class. My base looks like:

public abstract class BaseUIViewController : UIViewController
{
   public BaseUIViewController() : base() { }

   public BaseUIViewController(..) : base(..) { }
}

My controller inherits from this and defines a constructor like:

public class MyController : BaseUIViewController
{

   public MyController(ISOmeService service, IOtherService service)
   {
      ..
   }

    override ViewDidLoad(..) { .. }

}

TinyIOC creates the instance of the conntroller and supplies the constructor services. For some reason, ViewDidLoad runs before the constructor when I do this. When I remove the base class definition, it works with no issues.

Any idea why a base class causes the issues? I can logically assume it has to do with the objective-c compilation, but is there a workaround?

Thanks.

like image 324
Brian Mains Avatar asked Aug 28 '13 21:08

Brian Mains


1 Answers

Don't touch the Controller's View property in the constructor as this will trigger ViewDidLoad.

like image 125
Oliver Weichhold Avatar answered Oct 15 '22 16:10

Oliver Weichhold