Monotouch:异步加载 XIB
我想知道调用外部 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 ();
}
非常感谢。此致。
I would like to know what is the right manner for calling external XIB.
The method MonoTouch.Foundation.NSBundle.MainBundle.LoadNib
loads a XIB in a synchronous way but, in this manner, I can't override ViewDidLoad
method.
In particular, my goal is to crete a custom UIViewController
and load a XIB created in IB (this element is an item that is attached to a Superview). Then I would attach a tap action on the custom UIView
. Without overriding ViewDidLoad
method I'm not able to do it.
How can I find a good tutorial to understand all the different constructor which I can utilize into a UIViewController
?
For example, Could you explain these ctors?
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 ();
}
Thank you very much. Best Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您尝试做的概念就像更改 CocoaTouch 中默认事件和操作流的行为。
问题是,ViewDidLoad 正是您应该进行初始化的地方,而不是在构造函数本身中,将 NIB 加载保留在框架上,并按预期处理 ViewDidLoad 。
阅读苹果的开发文档确实很有帮助,这在开始时对我帮助很大: https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html
The concept you try to do seems to me like changing the behavior of the default event and action flow in CocoaTouch.
The thing is, that ViewDidLoad is exactly the place where you should do the initialization, not in the constructor itself, leave the NIB loading on the framework and just handle the ViewDidLoad as it is intended.
It really helps to read the apple's development documentation, this helped me a lot at the start: https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html