【问题标题】:instantiateViewControllerWithIdentifier crashes appinstanceViewControllerWithIdentifier 使应用程序崩溃
【发布时间】:2012-08-25 07:49:25
【问题描述】:

我正在尝试使用下图中显示的代码 sn-p 实例化 MainStoryBoard.storyboard 中定义的 ViewController。我还为控制器分配了一个标识符,但应用程序崩溃了,图片中显示的错误是“Storyboard 不包含具有标识符 masterViewController 的控制器”,尽管您可以在图片中清楚地看到它在那里。 任何帮助将不胜感激。

请注意,以下解决方案对我不起作用:Crash with instantiateViewControllerWithIdentifier

以下是确认情节提要对象与从视图控制器检索并用于实例化ViewControllerWithIdentifer: 相同的快照。 情况描述:我正在尝试开发一个自定义的 SplitViewController(从 UIViewController 继承)。这个 UIViewController 是纯程序化的,即不基于 IBInterface 布局。然而,对于它的孩子,即 MasterViewController 和 DetailViewController,我已经在 IBInterface 中进行了布局。现在,我在 SplitViewController 中检索一个 UIStoryboard 对象(纯程序化对象),并将其传递给第一张图片中显示的实用程序类,该类使用它基于 Storyboard 中的布局实例化 MasterViewController。

【问题讨论】:

    标签: ios5 uiviewcontroller uistoryboard


    【解决方案1】:

    嗯,看起来应该可以了。

    试试这个:

    • 清理项目并重建
    • 检查storyboard 是否包含正确故事板的实例

    由 shaffooo 修复(来自下面的 cmets)

    我重建了我的故事板,它解决了我遇到的问题。

    【讨论】:

    • 感谢您的回复。我使用storyboard.DebugDescription 来确认相同的故事板对象用于实例化从splitviewcontroller(自定义UIViewController)中检索到的viewcontroller,请参阅问题编辑中的图片。这是UIStoryboard * storybd = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; 的代码。我要提到的一件事是,我在其中检索情节提要对象的 viewController 是以编程方式设计的,并且没有情节提要布局。这会是个问题吗?。
    • 它实际上是一个视图控制器,我试图将其用作容器视图控制器,而我试图实例化的视图控制器确实具有情节提要布局。如果您不清楚,请告诉我。
    • 显然我不知道...您可以检查的一件事是情节提要中的标识符“masterViewController”是否可能在末尾包含一个空格,例如“masterViewController”。这可能会导致错误
    • 嗯,我检查了标识符名称是否正确仍然无法正常工作。无论如何,谢谢。
    • 如果您尝试访问它会怎样?来自您的应用委托 - 仅用于测试。 [[UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil] instantiateViewControllerWithIdentifier:@"masterViewController"] - 这行得通吗?
    【解决方案2】:

    尝试将您的 ViewController 类的相同名称写入 IB 中的“StoryBoard ID”。然后使用相同的字符串编辑您的 instantiateViewControllerWithIdentifier 方法的参数:

    yourVCName *startingViewController = (yourVCName *)[self.storyboard instantiateViewControllerWithIdentifier:@"yourVCName"];

    【讨论】:

      猜你喜欢
      • 2017-11-10
      • 2012-08-18
      • 2012-02-12
      • 2014-03-18
      • 2014-11-14
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多