简体   繁体   English

转到另一个故事板 Swift

[英]Segue to Another Storyboard Swift

I am attempting to segue to another storyboard programmatically, but every time I've tried the view loads with a black screen with no content.我试图以编程方式转到另一个故事板,但是每次我尝试加载视图时,都会显示一个没有内容的黑屏。

Here's the code I've been working with:这是我一直在使用的代码:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let startingView = storyboard.instantiateViewControllerWithIdentifier("HomeScreenView")
self.showViewController(startingView, sender: self)

I've created the reference on the Origin's Storyboard of the Destination Storyboard and have also tried to call:我已经在目标故事板的起源故事板上创建了参考,并且还尝试调用:

performSegueWithIdentifier("changeover", sender: self)

Any thoughts and suggestions would be greatly appreciated.任何想法和建议将不胜感激。

I've haven't had issues using Storyboard References with segues.我在使用带有 segue 的 Storyboard References 时没有遇到问题。 Here are the steps I've followed to get it working:以下是我为使其正常工作而遵循的步骤:

1) In the storyboard with the source view controller, drag a storyboard reference onto the canvas. 1) 在带有源视图控制器的情节提要中,将情节提要引用拖到画布上。

2) Set the reference to point to the correct storyboard name and view controller in the attribute inspector 2) 在属性检查器中将引用设置为指向正确的故事板名称和视图控制器

3) Ctrl+drag from the source's view controller icon (in the top bar of the scene) to the storyboard reference in order to create a segue. 3) Ctrl+从源的视图控制器图标(在场景的顶部栏中)拖动到情节提要参考以创建转场。

4) Set the segue to "Show" and give it the identifier "Test" in the attribute inspector 4)将segue设置为“Show”并在属性检查器中为其指定标识符“Test”

5) In your source view controller's code, at the appropriate location where you want it triggered, add the line: 5) 在源视图控制器的代码中,在您希望触发它的适当位置,添加以下行:

performSegueWithIdentifier("Test", sender: self)

That should be everything needed for the segue to be called programmatically!这应该是以编程方式调用 segue 所需的一切!

"MyStoryBoard" this is the storyboard name where you want to go "StoryboardId" this is the controller id which i want to show after segue. “MyStoryBoard”这是你想要去的故事板名称“StoryboardId”这是我想在segue之后显示的控制器ID。

let storyboard = UIStoryboard(name: "Service", bundle: nil)
    let myVC = storyboard.instantiateViewController(withIdentifier: "ProfileTimelineVC") as! ProfileTimelineVC
    self.present(myVC, animated: true, completion: nil)

In AppDelegate append var window: UIWindow?在 AppDelegate 中追加 var 窗口:UIWindow?

    let storyboard = UIStoryboard(name: "Registration", bundle: nil)
    let registrationvc = storyboard.instantiateViewController(withIdentifier: 
        "RegistrationViewController") as! RegistrationViewController
    self.window?.rootViewController?.present(registrationvc, animated: true, 
    completion: nil)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM