views:

26

answers:

1

If I want to use a custom view object with my view controller, instead of just using the one that's initialized by default, can I just assign it to the view controller's View property. For example, is the following the correct/safe approach?

public class MyView : UIView
{
}

public class MyController : UIViewController
{
    // Constructors.

    public MyController()
    {
        View = new MyView();
    }
}

Seems to work in a simple test, but I don't want to be introducing any time-bombs.

Or, should I be adding my custom view as a subview of the existing view in ViewDidLoad?

+1  A: 

You should be adding the custom views as subviews.

public class MyView : UIView
{
}

public class MyController : UIViewController
{
    public override void ViewDidLoad()
    {
        var myView = new MyView();
        this.View.AddSubview(myView);
    }
}
Kevin McMahon