Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to apply condition based custom segue in storyboard

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

like image 222
Vikas Ojha Avatar asked May 31 '12 03:05

Vikas Ojha


People also ask

How do you perform a segue?

Fortunately, it only takes two steps. First, select a segue in your storyboard, then go to the attributes inspector and give it a name such as “showDetail”. Technically the sender parameter is whatever triggered the segue, but you can put whatever you want in there.

How do I set the identifier for Viewcontroller in storyboard?

Step 1: Set a Storyboard IDIn the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.


1 Answers

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.
like image 141
Jon Hess Avatar answered Nov 15 '22 08:11

Jon Hess