【问题标题】:Monotouch: load XIB asynchronouslyMonotouch:异步加载 XIB
【发布时间】: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


    【解决方案1】:

    在我看来,您尝试执行的概念就像更改 CocoaTouch 中默认事件和操作流的行为。

    问题是,ViewDidLoad 正是您应该进行初始化的地方,而不是在构造函数本身中,将 NIB 加载留在框架上并按预期处理 ViewDidLoad。

    阅读苹果的开发文档真的很有帮助,这对我一开始帮助很大:https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html

    【讨论】:

      猜你喜欢
      • 2011-03-31
      • 2013-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多