【问题标题】:Initiating view controller through self.storyboard crash通过 self.storyboard 崩溃启动视图控制器
【发布时间】:2018-03-20 07:46:23
【问题描述】:

我在我的项目中使用故事板引用。当我尝试使用 self.storyboard 加载视图控制器时,它崩溃了。但是当我创建了一个新的故事板实例并尝试加载它时,它可以完美运行。

另一件事是没有情节提要参考,它也适用于第一种情况。

我使用的是 Xcode 7.3.1。

使用 self.storyboard。崩溃了

guard let registerViewController = self.storyboard?.instantiateViewControllerWithIdentifier(Sto‌ryboardIdentifier.Re‌gistration) as? RegisterVC else { return }

这是 UIStoryboard 的实例。它有效。

let mainStoryBoard = UIStoryboard.init(name: "Main", bundle: nil)

    guard let registerViewController = mainStoryBoard.instantiateViewControllerWithIdentifier(StoryboardIdentifier.Registration) as? RegisterVC else {
        return
    }

【问题讨论】:

  • 您应该添加导致崩溃的代码。还有崩溃报告。
  • 显示代码,崩溃发生在哪里?
  • guard 让 registerViewController = self.storyboard?.instantiateViewControllerWithIdentifier(StoryboardIdentifier.Registration) 作为? RegisterVC else { return }
  • 在你的问题中添加代码,而不是在 cmets,Edit your Question
  • @John 他说“他正在创建故事板的实例”,使用 self 是不同的事情。如果您的 VC 在 diff 故事板上,则必须创建实例,否则如果它们相同,则无需创建实例,self 将起作用。

标签: ios objective-c iphone xcode uistoryboard


【解决方案1】:

由于您使用的是 Storyboard References,因此我将在这里冒险,并说 mainStoryBoard 和 self.storyboard 引用了不同的 StoryBoard,而阻塞的 StoryBoard 不包含名为 StoryboardIdentifier.Registration 的 ViewController。

或者 StoryboardIdentifier.Registration 在每种情况下都包含不同的值。

【讨论】:

    猜你喜欢
    • 2014-03-19
    • 2011-01-21
    • 2011-11-21
    • 2012-11-03
    • 2017-04-10
    • 1970-01-01
    • 2018-07-26
    • 2012-03-11
    • 2011-06-21
    相关资源
    最近更新 更多