ios - 从 AppDelegate 加载屏幕

标签 ios swift storyboard

在点击我的应用程序的深层链接后,我尝试从 AppDelegate 加载屏幕。不幸的是它使我的应用程序崩溃了。

我使用此代码尝试呈现 UI:

self.window = UIWindow(frame: UIScreen.main.bounds)
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let bestViewController: BestViewController = mainStoryboard.instantiateViewController(withIdentifier: "BestViewController") as! BestViewController
bestViewController.selectedBrocode = result
let navigationViewController = BroNavigationViewController(rootViewController: bestViewController)
self.window?.rootViewController = navigationViewController

这在我的控制台中打印:

2017-08-08 16:00:48.685 BroCode[17567] <Warning> [Firebase/Analytics][I-ACS031011] Root view controller not found
fatal error: unexpectedly found nil while unwrapping an Optional value
2017-08-08 16:00:48.687130+0800 BroCode[17567:6659940] fatal error: unexpectedly found nil while unwrapping an Optional value

这是堆栈跟踪:

libswiftCore.dylib`function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never:
    0x1012ec3d0 <+0>:   stp    x26, x25, [sp, #-0x50]!
    0x1012ec3d4 <+4>:   stp    x24, x23, [sp, #0x10]
    0x1012ec3d8 <+8>:   stp    x22, x21, [sp, #0x20]
    0x1012ec3dc <+12>:  stp    x20, x19, [sp, #0x30]
    0x1012ec3e0 <+16>:  stp    x29, x30, [sp, #0x40]
    0x1012ec3e4 <+20>:  add    x29, sp, #0x40            ; =0x40 
    0x1012ec3e8 <+24>:  mov    x19, x6
    0x1012ec3ec <+28>:  mov    x20, x5
    0x1012ec3f0 <+32>:  mov    x21, x4
    0x1012ec3f4 <+36>:  mov    x22, x3
    0x1012ec3f8 <+40>:  mov    x23, x2
    0x1012ec3fc <+44>:  mov    x24, x1
    0x1012ec400 <+48>:  mov    x25, x0
    0x1012ec404 <+52>:  adr    x8, #0xf11fc              ; protocol descriptor for Swift._DefaultCustomPlaygroundQuickLookable + 136
    0x1012ec408 <+56>:  nop    
    0x1012ec40c <+60>:  add    x0, x8, #0x10             ; =0x10 
    0x1012ec410 <+64>:  mov    w1, #0x28
    0x1012ec414 <+68>:  orr    w2, wzr, #0x7
    0x1012ec418 <+72>:  bl     0x1012ec750               ; swift_rt_swift_allocObject
    0x1012ec41c <+76>:  mov    x8, x0
    0x1012ec420 <+80>:  stp    x22, x21, [x8, #0x10]
    0x1012ec424 <+84>:  strb   w20, [x8, #0x20]
    0x1012ec428 <+88>:  str    w19, [x8, #0x24]
    0x1012ec42c <+92>:  adr    x3, #0x40440              ; partial apply forwarder for Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never).(closure #2)
    0x1012ec430 <+96>:  nop    
    0x1012ec434 <+100>: mov    x0, x25
    0x1012ec438 <+104>: mov    x1, x24
    0x1012ec43c <+108>: mov    x2, x23
    0x1012ec440 <+112>: mov    x4, x8
    0x1012ec444 <+116>: bl     0x1011cd4dc               ; function signature specialization <preserving fragile attribute, Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> () to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> ()]> of generic specialization <preserving fragile attribute, ()> of Swift.StaticString.withUTF8Buffer <A> ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
->  0x1012ec448 <+120>: brk    #0x1

屏幕截图:

enter image description here

最佳答案

请检查storyboard中的Storyboard ID是否为BestViewController。

enter image description here

也请尝试注释掉

bestViewController.selectedBrocode = result

关于ios - 从 AppDelegate 加载屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45562610/

相关文章:

swift - 在 swift 3 中使用 % 设置图像位置

swift - 在 cellForRowAt 中显示正确的信息

ios - iOS文档目录大小限制

ios - 在 iOS 中将 ImageView 放在另一张图像上

ios - 仅在纵向获取屏幕宽度和高度

swift - 定时器完成 block 中的变量未更新

ios - 无法从天气 api 获取 json。 iOS系统

ios - Storyboard和续集 : How does the presenting VC know when the presented VC dismisses itself?

ios - 移动到另一个没有 UINavigationController 的 Storyboard

objective-c - XCode/OS X : Storyboard Minimum Requirements