【问题标题】:How do I fix problems with opening views如何解决打开视图的问题
【发布时间】:2022-01-20 01:37:32
【问题描述】:

我遇到了一个问题,我打开第二个视图控制器的功能不起作用并且正在崩溃。 这是导致它崩溃的代码:

        let NewRecipe = self.storyboard?.instantiateViewController(withIdentifier: "NewRecipeVC")as! NewRecipe
        present(NewRecipe,animated: true)

它给了我一个错误:

Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1859c41a8)

我要做的就是打开名为“NewRecipeVC”的视图控制器

【问题讨论】:

  • 您是否为该 VC 设置了 Storyboard ID?

标签: swift xcode uiviewcontroller storyboard


【解决方案1】:

消息“EXC_BREAKPOINT”听起来像是您在代码中设置了断点,而不是您有错误。

请注意,您应该避免使用 ! 进行强制转换。如果您的视图控制器不是预期的类型,那将会崩溃。请改用if letguard let

【讨论】:

  • 现在吐了:Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value,这里是代码if let vc = self.storyboard?.instantiateViewController(withIdentifier: "NewRecipeVC") present(vc,animated: true)
猜你喜欢
  • 2020-04-23
  • 2011-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-26
相关资源
最近更新 更多