我有一个非常简单的问题 - 这很简单,我发现它有点尴尬。当我无法从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.
}
答案 0 :(得分:1)
使用View.AddSubview()
this.View.AddSubview(btnSubmit);