0

我有一个非常简单的问题——太简单了,我觉得有点尴尬。当我无法从 appdelegate 类访问窗口时,如何向视图添加控件。这是我从中遍历的屏幕。(这只是 viewdidload 方法)

我以为 window.AddSubview(btnSubmit); 会起作用,但在 appdelegate 类之外无法识别窗口。

public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        var btnSubmit = UIButton.FromType (UIButtonType.RoundedRect);
        var frame = new System.Drawing.RectangleF (35f, 30f, 250f, 40f);
        btnSubmit.Frame = frame;
        btnSubmit.SetTitle ("Return Home", UIControlState.Highlighted);

        btnSubmit.TouchUpInside += (sender, e) =>
        {
            btnSubmit.SetTitle("Clicked", UIControlState.Normal);
        };


        // Perform any additional setup after loading the view, typically from a nib.
    }
4

1 回答 1

1

使用 View.AddSubview()

this.View.AddSubview(btnSubmit);
于 2013-06-07T20:45:19.847 回答