[英]Swift Navigation bar not appearing when storyboard is referenced after login
當我為應用程序啟動構建時,登錄和注冊工作正常,但是當它傳輸到 HomeVC storyboard 時,它顯示為空。 為了確保正確引用它,我在上面放置了標簽,而那些在構建過程中出現的標簽實際上仍然不可見的是導航欄。 請幫助:)
登錄和注冊中如何引用 HomeVC storyboard
登錄:
else {
let homeViewController = self.storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
self.view.window?.rootViewController = homeViewController
self.view.window?.makeKeyAndVisible()
報名:
func transitionToHome(){
let homeViewController = storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
view.window?.rootViewController = homeViewController
view.window?.makeKeyAndVisible()
你可以嘗試使用segue
// This is used to perform the segue with the approporiate identifier
self.performSegue(withIdentifier: "Your unique identifer of the seugue", sender: self)
// Prepare for segue is used if you want to modify some properities in the desintation viewcontroller
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Your identifier of the segue" {
// This is used to fetch the destination and cast it to pass over the values
if let dc = segue.destination as? YourClassOfTheDestination {
// Here can you type into dc and pass over the values
//Example
dc.curentFruit = "Pear"
}
}
}
這是關於如何在 storyboard 中指定 segue 的自定義標識符的圖像。 這是圖像
如果您不希望導航欄在某些屏幕中可見,您可以簡單地使用:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.isHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.isHidden = false
}
記得在視圖消失時讓它再次可見。
很好的問題,希望答案有幫助!
我相信問題是您正在使視圖 controller 成為關鍵 window 而您沒有添加導航 controller。 嘗試將主視圖控制器的導航 controller 設為鍵 window。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.