how to apply condition based custom segue in storyboard

混江龙づ霸主 提交于 2019-12-04 13:22:06

问题


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


回答1:


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.


来源:https://stackoverflow.com/questions/10827203/how-to-apply-condition-based-custom-segue-in-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!