ios – LaunchScreen.storyboard无法打开Main.storyboard导航控制器

前端之家收集整理的这篇文章主要介绍了ios – LaunchScreen.storyboard无法打开Main.storyboard导航控制器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚开始使用 Swift(新手)开发一个新的应用程序.我有

> LaunchScreen.storyboard只有我的启动画面的图像
>我有一个Main.storyboard,导航控制器连接到两个segues,Home和Registration.
>在ViewController.swift中,在viewDidLoad中我决定调用哪个segue
>我的Main.Storyboard没有rootViewController,我需要决定在运行时显示哪个viewController.

if (Settings.hasRegistrationCompleted()) {
    performSegue(withIdentifier: "Home",sender: nil)
} else {
    performSegue(withIdentifier: "Registration",sender: nil)
}

我的问题

>如果(Settings.has和断点永远不会到达此处),我会在第一行放置一个断点
> LaunchScreen仅持续2秒(在我的模拟器上测试)如何增加

编辑

我将Main设置为我项目的主界面.我做了一个Clean build并再次尝试,但没有工作.

以下是Main.Storyboard

enter image description here

解决方法

在这里你需要识别两件事

第一

检查您的故事板名称Main.storyboard是否正确附加在您的目标中 – >一般 – >部署信息 – >主接口,例如像这样

enter image description here

第二

检查与导航控制器连接的初始VC并确保初始VC为根控制器

enter image description here

更新答案

最初为每个VC设置Stroryboard ID

enter image description here

在appdelegate中更改Root控制器之后

func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.main.bounds)
    // Override point for customization after application launch.
     let storyboard = UIStoryboard(name: "Main",bundle: nil)
    let rootViewController: UIViewController?
     if (Settings.hasRegistrationCompleted()) {
     rootViewController = storyboard.instantiateViewController(withIdentifier: "HomeVC")
    }else
     {
         rootViewController = storyboard.instantiateViewController(withIdentifier: "RegistrationVC")
    }
     let navigation = UINavigationController(rootViewController: rootViewController!)
    self.window?.rootViewController = navigation
    self.window?.makeKeyAndVisible()
    return true
}

猜你在找的Xcode相关文章