Segue到另一个故事板Swift

时间:2016-07-20 17:22:56

标签: ios swift xcode-storyboard

我试图以编程方式转换到另一个故事板,但每次我都尝试使用没有内容的黑屏加载视图。

以下是我一直在使用的代码:

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

我在目的地故事板的Origin的故事板上创建了引用,并且还尝试调用:

performSegueWithIdentifier("changeover", sender: self)

非常感谢任何想法和建议。

3 个答案:

答案 0 :(得分:6)

我在使用带有segues的Storyboard References时遇到了问题。以下是我为使其发挥作用而采取的步骤:

1)在具有源视图控制器的故事板中,将故事板引用拖到画布上。

2)将引用设置为指向正确的故事板名称并在属性检查器中查看控制器

3)按住Ctrl键并从源视图控制器图标(在场景的顶部栏中)拖动到故事板参考,以创建一个segue。

4)将segue设置为" Show"并给它标识符"测试"在属性检查器

5)在源视图控制器的代码中,在您想要触发它的适当位置添加以下行:

performSegueWithIdentifier("Test", sender: self)

这应该是以编程方式调用segue所需的一切!

答案 1 :(得分:1)

“ 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)

答案 2 :(得分:1)

在AppDelegate中追加变量窗口: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)
相关问题