如何在情节提要中应用基于条件的自定义segue [英] how to apply condition based custom segue in storyboard

查看:116
本文介绍了如何在情节提要中应用基于条件的自定义segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理情节提要,该情节提要在第一个视图上具有多个视图,并且放置了一个条件,我希望条件满足时才应该进行导航



为此使用了自定义segue,但是无论我的条件是否满足,它都可以导航到新视图。



我已经在自定义segue类中创建了方法

 -(void)perform {

NSLog(@ source%@,self.sourceViewController);
NSLog(@ dest%@,self.destinationViewController);

UIViewController * sVC = self.sourceViewController;
UIViewController * dVC = self.destinationViewController;

[sVC.navigationController pushViewController:dVC animation:YES];


}

如果结果为1然后只有它应该导航。 prepareforsegue或initwithsegue会为我提供任何帮助吗?

解决方案

您是说您只想在条件为真时执行segue吗?



如果这样,则不要直接从控件或表格单元中创建序列,而应创建无触发序列。无触发序列是将视图控制器作为源,并且永远不会自动触发。取而代之的是,您可以在任何时候以编程方式触发它,包括从IBAction中触发它。



要创建无触发序列,请开始控制并从中的包含视图控制器图标拖动该序列场景停靠在场景的底部。像往常一样拖到目标场景,然后选择segue类型。选择segue,然后在检查器中选择一个segue标识符。您可以将任何想要的对象传递给发件人,包括nil。如果发件人对您没有用,则传递nil。



因此,总结来说:




  • 从视图控制器到目标场景创建无触发的segue

  • 在检查器中为segue设置标识符

  • 在运行时,和表单代码,当您想触发segue时,请调用-[UIViewController performSegueWithIdentifier:sender:]。


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

- (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

解决方案

Are you saying that you only want to perform the segue if a condition is true?

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.

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.

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.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆