[英]what's different LaunchScreen.storyboard and Main.storyboard in iOS?
[英]LaunchScreen.storyboard not opening Main.storyboard Navigation Controller
我剛剛開始使用Swift(新手)開發一個新的應用程序。 我有
Navigation Controller
連接到兩個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) }
我的問題
if (Settings.has
和斷點永遠不會到達此處),我在第一行放置斷點 編輯
我將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)
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.