我正在尝试做一个应用程序,将有一个家庭按钮在每个视图,但我正在寻找一种方式导航到主屏幕点击这个按钮,而不做一个“物理”链接的每个屏幕上的StoryBoard到主屏幕。
我试着使用以下代码:
@IBAction func btnGoInicio(_ sender: Any) {
let page = MainVC()
present(page, animated: true, completion: nil)
}但是这次在黑屏上的撞击,有人知道我怎么做的?提前感谢!
发布于 2018-09-26 22:06:25
您必须从故事板实例化viewController,这样:
@IBAction func btnGoInicio(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil) // If you have other storyboard instead of Main, use it
if let page=self.storyboard?.instantiateViewControllerWithIdentifier("YOU_IDENTIFIER") as! MainVC{
//You MUST SET THE VIEW CONTROLLER IDENTIFIER "YOU_IDENTIFIER" FROM INSPECTOR INTO STORYBOARD
self.present(page, animated: true, completion: nil)
}
}发布于 2018-09-26 20:57:07
在代码中使用segue时,应使用此方法。
func performSegue(withIdentifier identifier: String,
sender: Any?)确保您在故事板中设置了标识符,以便以后可以在标识符参数中调用它们。
https://stackoverflow.com/questions/52524596
复制相似问题