我正在尝试在点击Deeplink进入我的应用程序后从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
截图:
答案 0 :(得分:0)
答案 1 :(得分:0)
只需选择“使用Storyboard Id&#39;
答案 2 :(得分:0)
尝试替换它:
self.window?.rootViewController = navigationViewController
用这个:
if let window = self.window, let rootViewController = window.rootViewController {
var currentController = rootViewController
while let presentedController = currentController.presentedViewController {
currentController = presentedController
}
currentController.present(navController, animated: true, completion: nil)
}