How to apply custom mode based on conditions in a storyboard

I am working on clipping files that have a couple of views on the first scan, the condition is placed, I want if the condition is satisfied, then only navigation should happen

For this, I used Custom segue, but regardless of whether my condition is satisfactory or not, it goes to a new view.

I created a method in a 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 a condition if the result is 1, and only it should move. Woul prepareforsegue or initwithsegue will give me any help

+6
source share
1 answer

You say you only want to execute segue if the condition is true?

If so, instead of creating a segue directly from a control cell or table, create a non-stop segment. In trigger mode, segue has a view controller as a source, and it will not work automatically. Instead, you can run it programmatically at any time convenient for you, including from IBAction.

To create a goalless session, start control + drag the segue from the controller icon in the scene dock at the bottom of the scene. Drag to the destination scene as usual and select a segment type. Select segue, and in the inspector, select the segue identifier.

At run time, when you want to execute segue, call - [UIViewController performSegueWithIdentifier: sender:]. You can transfer any object that you want to send to the sender, including nil. If the sender does not suit you, skip nil.

So in short:

  • Create a trigger session from the view controller to the destination.
  • Set session id in inspector
  • At run time and form code, call [UIViewController performSegueWithIdentifier: sender:] when you want to invoke the session.
+30
source

Source: https://habr.com/ru/post/917068/


All Articles