xcode 如何在情节提要中应用基于条件的自定义转场
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10827203/
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
how to apply condition based custom segue in storyboard
提问by Vikas Ojha
i am working on storyboards which has couple of views on first view a condition is placed i want if the condition satisfies then only navigation should happen
我正在研究故事板,它在第一次查看时有几个视图,如果条件满足,我想要一个条件,那么只应该发生导航
For this i have used Custom segue but no matter my condition satisfies or not it navigates to new view.
为此,我使用了自定义转场,但无论我的条件是否满足,它都会导航到新视图。
I have created method in custom segue class
我在自定义 segue 类中创建了方法
- (void) perform{
NSLog(@"source %@",self.sourceViewController);
NSLog(@"dest %@",self.destinationViewController);
UIViewController *sVC=self.sourceViewController;
UIViewController *dVC=self.destinationViewController;
[sVC.navigationController pushViewController:dVC animated:YES];
}
I want to set condition if result is 1 then only it should navigate. Woul prepareforsegue or initwithsegue provide me any help
如果结果为 1,我想设置条件,那么只有它应该导航。将prepareforsegue 或initwithsegue 为我提供任何帮助
回答by Jon Hess
Are you saying that you only want to perform the segue if a condition is true?
您是说您只想在条件为真时执行 segue 吗?
If so, instead of creating the segue directly from a control or table cell, create a triggerless segue. A triggerless segue has the view controller as its source, and it won't ever fire automatically. Instead you can fire it programmatically any time you like, including from an IBAction.
如果是这样,请不要直接从控件或表格单元格创建转场,而是创建无触发转场。无触发器转场将视图控制器作为其来源,并且永远不会自动触发。相反,您可以随时以编程方式触发它,包括从 IBAction 触发。
To create a triggerless segue, start control+dragging the segue from the containing view controller icon in the scene dock at the bottom of the scene. Drag to the destination scene like normal, and pick the segue type. Select the segue, and in the inspector, choose a segue identifier.
要创建无触发器转场,请从场景底部的场景停靠栏中的包含视图控制器图标开始控制并拖动转场。像往常一样拖动到目标场景,然后选择转场类型。选择 segue,然后在检查器中,选择一个 segue 标识符。
At runtime, when you want to perform the segue, invoke -[UIViewController performSegueWithIdentifier:sender:]. You can pass any object you'd like for the sender, including nil. If the sender has no use to you, pass nil.
在运行时,当你想要执行 segue 时,调用 -[UIViewController performSegueWithIdentifier:sender:]。您可以为发件人传递任何您想要的对象,包括 nil。如果发件人对你没有用,则传递 nil。
So, in summary:
所以,总结一下:
- Create a triggerless segue from the view controller to the destination scene
- Set an identifier for the segue in the inspector
- At runtime, and form code, call -[UIViewController performSegueWithIdentifier:sender:] when you want to trigger the segue.
- 创建从视图控制器到目标场景的无触发器转场
- 在检查器中为 segue 设置标识符
- 在运行时和表单代码中,当您想要触发 segue 时调用 -[UIViewController performSegueWithIdentifier:sender:]。