开发者

In MonoTouch, how do I assign a custom view to my view controller?

开发者 https://www.devze.com 2023-01-12 05:37 出处:网络
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,

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 c开发者_开发百科ustom view as a subview of the existing view in ViewDidLoad?


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);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消