xcode 手动使用 Segue
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12717757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Segue Manually
提问by Flatlyn
I need to create two Segue's from the same button, and then I want to programatically choice which one to use based on device orientation. The problem I'm having is that you can only seem to create one segue from a button to another view so when I add the second one it just changes the first.
我需要从同一个按钮创建两个 Segue,然后我想根据设备方向以编程方式选择使用哪一个。我遇到的问题是,您似乎只能从按钮到另一个视图创建一个 segue,因此当我添加第二个时,它只会更改第一个。
How do you add a segue that either isn't linked to a button etc so I can do programatically or how are you supposed to do this. I want to have two views that get dynamically picked based on orientation rather than moving the objects based via code when rotated as there is alot of objects and custom stuff that would make it much simplier just to have two views.
您如何添加未链接到按钮等的转场,以便我可以以编程方式进行操作,或者您应该如何执行此操作。我希望有两个视图可以根据方向动态选择,而不是在旋转时通过代码移动对象,因为有很多对象和自定义的东西会让只有两个视图变得更简单。
回答by Marty
You'd have to trigger the segue manually. Hook up the button to a method, then make two segues, one from each view controller to the other in your storyboard, then give it an identifier in IB, then in your method you can call "performSegueWithIdentifier:".
您必须手动触发 segue。将按钮连接到一个方法,然后制作两个 segue,一个从每个视图控制器到故事板中的另一个,然后在 IB 中给它一个标识符,然后在你的方法中你可以调用“performSegueWithIdentifier:”。
Additional Info
附加信息
To make a manual segue, control-click from the view controller object in IB to another view controller and the box will pop up as "Manual Segue". Just make sure it has an identifier.
要进行手动转场,请从 IB 中的视图控制器对象按住 Control 单击到另一个视图控制器,该框将弹出为“手动转场”。只要确保它有一个标识符。
回答by timquinn
I would think you could have the button trigger an IBAction wherein you could make a choice based on orientation and then trigger the appropriate segue programmatically.
我认为您可以让按钮触发 IBAction,您可以在其中根据方向进行选择,然后以编程方式触发适当的 segue。

