【问题标题】:(lldb) po self.storyboard nil(lldb) po self.storyboard nil
【发布时间】:2016-06-06 15:07:22
【问题描述】:

UIViewController 如何/何时可以返回 self.storyboard nil。

我正在尝试使用以下方法实例化 ViewController:

self.storyboard!.instantiateViewControllerWithIdentifier


但是 self.storyboard 为零?
注意:plist 设置为正确的故事板。

【问题讨论】:

  • If the view controller was not instantiated from a storyboard, this property is nil.(来自文档)。您的UIViewController 是如何创建的?
  • 你是对的,ViewController 是在代码中创建的,因此故事板是 nil。答案是创建您自己的实例。
  • 这听起来可能是 X/Y 问题。

标签: ios swift interface-builder uistoryboard


【解决方案1】:

根据Apple documentationUIViewControllerstoryboard 属性表示视图控制器源自的情节提要。如果视图控制器不是从情节提要中实例化的,它返回一个可选的UIStoryboard 实例nil

【讨论】:

    【解决方案2】:

    试试这个:

    let localStoryboard = UIStoryboard(name: "Main", bundle: nil)
    

    【讨论】:

    • 这实际上对我有用。我只在我的应用程序的某些部分使用故事板 --- 不包括 rootViewController。
    • 不要轻视,因为这是一种有效的方法。
    猜你喜欢
    • 2014-09-07
    • 2020-02-05
    • 2018-06-28
    • 2011-10-11
    • 2021-03-07
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 2014-09-09
    相关资源
    最近更新 更多