Monotouch:异步加载 XIB

发布于 2024-10-20 14:09:18 字数 847 浏览 7 评论 0原文

我想知道调用外部 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2024-10-27 14:09:18

在我看来,您尝试做的概念就像更改 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文