【发布时间】:2011-07-08 07:11:57
【问题描述】:
我想知道调用外部XIB的正确方式是什么。
MonoTouch.Foundation.NSBundle.MainBundle.LoadNib 方法以同步方式加载 XIB,但在这种方式下,我无法覆盖 ViewDidLoad 方法。
特别是,我的目标是创建自定义UIViewController 并加载在 IB 中创建的 XIB(此元素是附加到 Superview 的项目)。然后我会在自定义UIView 上附加一个点击操作。如果不覆盖 ViewDidLoad 方法,我将无法做到。
我怎样才能找到一个很好的教程来理解我可以在UIViewController 中使用的所有不同的构造函数?
例如,您能解释一下这些角色吗?
public MyCustomView (IntPtr handle) : base(handle)
{
Initialize ();
}
[Export("initWithCoder:")]
public MyCustomView (NSCoder coder) : base(coder)
{
Initialize ();
}
public MyCustomView () : base("MyCustomView", null)
{
//---- this next line forces the loading of the xib file to be synchronous
MonoTouch.Foundation.NSBundle.MainBundle.LoadNib ("MyCustomView", this, null);
Initialize ();
}
非常感谢。最好的问候。
【问题讨论】:
标签: ios uiviewcontroller xamarin.ios xib lifecycle