没有故事板的 Segue [英] Segue without StoryBoard
本文介绍了没有故事板的 Segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个在每个视图上都有一个主页按钮的应用程序,但我正在寻找一种在单击此按钮时导航到主屏幕的方法,而不需要为每个屏幕上的物理"链接故事板到主屏幕.
I'm trying to do an app that will have a Home Button on each View, but I'm looking for a way to navigate to Home Screen on click this button, without make a "physical" link for each screen on StoryBoard to home screen.
我正在尝试使用此代码:
I'm try to use this code:
@IBAction func btnGoInicio(_ sender: Any) {
let page = MainVC()
present(page, animated: true, completion: nil)
}
但是这个黑屏崩溃,有人知道我该怎么做吗?提前致谢!
But this crash on a black screen, some one know how I can do it? Thanks in advance!
推荐答案
你必须从 storyboard 实例化一个 viewController,这样:
You have to instantiate a viewController from storyboard, this way:
@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)
}
}
这篇关于没有故事板的 Segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文