簡體   English   中英

LaunchScreen.storyboard無法打開Main.storyboard Navigation Controller

[英]LaunchScreen.storyboard not opening Main.storyboard Navigation Controller

我剛剛開始使用Swift(新手)開發一個新的應用程序。 我有

  1. LaunchScreen.storyboard只有我的啟動畫面的圖像
  2. 我有一個Main.storyboard, Navigation Controller連接到兩個segues ,Home和Registration。
  3. ViewController.swift ,在viewDidLoad我決定調用哪個segue
  4. 我的Main.Storyboard沒有rootViewController ,我需要決定在運行時顯示哪個viewController

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

我的問題

  1. if (Settings.has和斷點永遠不會到達此處),我在第一行放置斷點
  2. LaunchScreen只持續2秒(在我的模擬器上測試)如何增加它

編輯

我將Main設置為我項目的Main Interface 我做了一個Clean build並再次嘗試,但沒有工作。

以下是Main.Storyboard

在此輸入圖像描述

在這里你需要識別兩件事

第一

檢查您的故事板名稱Main.storyboard是否正確附加在您的Target -> general -> Deployment Info -> main Interface ,例如像這樣

在此輸入圖像描述

第二

檢查與導航控制器連接的初始VC並確保初始VC為根控制器

在此輸入圖像描述

更新答案

最初為每個VC設置Stroryboard ID

在此輸入圖像描述

在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
}

您還可以對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)
    }

  }
}

在那里你必須有一個View-Controller作為NavigationControllerRootVieController ,它必須用RootVieController初始化,如下面的截圖。 從登錄您需要segue到兩個View Controller。

喜歡以下

在此輸入圖像描述

因此,您需要在LoginViewController中檢查您是否已登錄。 或者您可以進行注冊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM