当我为应用程序启动构建时,登录和注册工作正常,但是当它转移到HomeVC故事板时,它似乎是空的。为了确保它被正确引用,我在上面贴上了标签,并且在构建过程中出现的标签实际上是导航栏。请帮助:)
如何在登录和注册中引用HomeVC故事板
登录名:
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"
}
}
}
这里是有关如何在情节提要中指定segue的自定义标识符的图像。 Here is the image
如果您不希望导航栏在某些屏幕上可见,您可以简单地使用:
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
}
请记住在视图消失时使其再次可见。
很好的问题,希望答案会有所帮助!