0

目前我正在加载具有该 NSBundle.MainBundle.LoadNib("NibName", this, null)功能的一些子视图的视图,但我手动添加加载视图的子视图 this.AddSubviews(this.subview1)

如何从 Nib 加载视图,这样我就不需要手动将子视图添加到当前视图?

编辑:现在我试图得到 LoadNib 函数的结果:

var res = NSBundle.MainBundle.LoadNib("ViewX",this,null);

var betterRes = Runtime.GetNSObject(res.ValueAt(0)) as Viewx;

现在“this”已经初始化了子元素的属性,但他的视图是空的。并且“betterRes”具有视图中的所有子视图,但子元素的所有属性均为空。只是为了澄清......每个子元素都是按钮或标签,并且有自己的看法。

4

1 回答 1

0

如果我正确理解你想要什么:从 nib 文件加载带有插座或动作的视图到主视图,这里是一个尝试:

//Load the view
var res = NSBundle.MainBundle.LoadNib("ViewX",this,null); 
// init your view with IntPtr
var betterRes = new Viewx(res.ValueAt(0)); 
//then use this view as main view
 this.View = betterRes;  //Or add subview: this.View.AddSubView(betterRes);

现在,您视图中的某些属性应该可以工作了。
希望这有帮助!

于 2012-09-16T11:12:58.013 回答