LaunchScreen.storyboard未打开Main.storyboard导航控制器

时间:2017-03-08 07:24:07

标签: ios swift xcode swift3

我刚刚开始使用Swift(新手)开发一个新的应用程序。我有

  1. LaunchScreen.storyboard只有我的启动画面的图像
  2. 我有一个Main.storyboard,Navigation Controller连接到两个segues,主页和注册。
  3. ViewController.swiftviewDidLoad内我决定拨打哪个电话
  4. 我的Main.Storyboard没有rootViewController,我需要决定在运行时显示哪个viewController

    if (Settings.hasRegistrationCompleted()) {
        performSegue(withIdentifier: "Home", sender: nil)
    } else {
        performSegue(withIdentifier: "Registration", sender: nil)
    } 
    
  5. 我的问题

    1. 我在第一行if (Settings.has上放置一个断点,断点永远不会到达
    2. LaunchScreen仅持续2秒(在我的模拟器上测试)如何增加它
    3. 修改

      我已将Main设置为我项目中的Main Interface。我做了Clean构建并再次尝试,但没有工作。

      以下是Main.Storyboard

      enter image description here

3 个答案:

答案 0 :(得分:5)

这里需要识别的两件事

<强>第一

检查您的情节提要名称Main.storyboard是否已正确附加在Target -> general -> Deployment Info -> main Interface中,例如

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
}

答案 1 :(得分:1)

您还可以对UINavigationController进行子类化并将其设置为故事板。删除segues(你不需要它们)

然后

class ViewController: UINavigationController {
  override func viewDidLoad() {
    super.viewDidLoad()

    if (Settings.hasRegistrationCompleted()) {
      let homeVC = self.storyboard?.instantiateViewController(withIdentifier: "HomeVC")
      self.setViewControllers([homeVC!], animated: false)
    }
    else {
      let regVC = self.storyboard?.instantiateViewController(withIdentifier: "RegistrationVC")
      self.setViewControllers([regVC!], animated: false)
    }

  }
}

答案 2 :(得分:1)

你的View-Controller RootVieController必须有一个NavigationController,并且必须使用arow初始化,如下面的屏幕截图所示。从登录您需要切换到两个View Controller。

喜欢关注

enter image description here

因此,您需要检查您已登录的LoginViewController。或者你可以选择注册