ios - 没有 Storyboard 的 Segue

标签 ios swift xcode segue uistoryboardsegue

我正在尝试制作一个在每个 View 上都有一个主页按钮的应用程序,但我正在寻找一种在单击此按钮时导航到主屏幕的方法,而不需要为每个屏幕创建“物理”链接 Storyboard到主屏幕。

我尝试使用此代码:

@IBAction func btnGoInicio(_ sender: Any) {
    let page = MainVC()
    present(page, animated: true, completion: nil)
}

但是黑屏崩溃,有人知道我该怎么做吗?提前致谢!

最佳答案

您必须从 Storyboard 中实例化 View Controller ,如下所示:

@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)
    }

}

关于ios - 没有 Storyboard 的 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52524596/

相关文章:

ios - -[__NSDictionaryM objectAtIndex :]: unrecognized selector sent to instance

ios - 如何从 NSURLSessionTask 获取响应字符串

ios - 应该在核心数据中有一个倒数

ios - 将库添加到 IOS 应用程序会导致可怕的构建失败

objective-c - 发送usb包osx

ios - 无法使用 '[item]' 类型的索引为 'item' 类型的值添加下标

ios - 为不同的开发者帐户签名时的代码签名 "No account for team"消息

ios - 如何为一定数量的设备分发 iOS 应用程序?

ios - NSTimer 更改间隔性能

ios - 更改方向时如何使 UITabbar selectionIndicatorImage 发生变化 - Swift