Set programmatic segue id

Let's say I have a ViewController with a textbox and a button.

I want to use unind segue so that I can get the textbox information to my other viewer after I clicked the button.

I want to use the PrepareForSegue method, so I could store the text from the textbox in the property before I have "m" left.

How do I manually configure the ID for my session? If it was a Bar button element, I could use IB to set an ID (like Save) and then use that. This is not the case, just a regular button.

0


source to share


2 answers


You cannot create segues programmatically. They can't exist without a storyboard.



See this question .

+4


source


You can easily add segue programmatically (without using a storyboard). In the source controller header file:

@property (nonatomic, strong) UIStoryboardSegue *segue;

      

In the original view controller implementation file, set the segue property as follows:

self.segue = [UIStoryboardSegue segueWithIdentifier:[NSString stringWithFormat:@"%lu", indexPath.item] source:self destination:[PlayerViewController sharedPlayerViewController] performHandler:^{
       // Insert whatever; nothing is needed for a basic segue
    }];

      

Also, in the source view controller, add the target controller setting and transition to the method prepareForSegue

:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// The code in this method both sets up the destination view controller and transitions to it; you could optionally do set up here only, and then transition in an overridden -(void)perform method. This way is more convenient.
     [(PlayerViewController *)segue.destinationViewController setView:[PlayerView sharedPlayerView]];
     PHAsset *phAsset = (PHAsset *)AppDelegate.assetsFetchResults[segue.identifier.integerValue];
     [AppDelegate.cacheManager requestAVAssetForVideo:phAsset options:AppDelegate.videoOptions resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
         [[PlayerView sharedPlayerView] addSubview:[PlayerControls sharedPlayerControls]];
         [[PlayerControls sharedPlayerControls] setDelegate:(PlayerViewController *)segue.destinationViewController];
         [[PlayerView sharedPlayerView] addSubview:[AppDelegate playerControlsLabel]];
         [(PlayerViewController *)segue.destinationViewController setupPlaybackForAsset:asset completion:^{
             [((AssetsCollectionViewController *)sender).navigationController presentViewController:(PlayerViewController *)segue.destinationViewController animated:TRUE completion:^{
             }];
         }];
     }];
}

      

Also, add this line anywhere in the source controller implementation file to execute the segue:

[self prepareForSegue:self.segue sender:self];

      

The method call prepareForSegue

can be performed inside the IBAction handler and elsewhere.



Note that the code that represents the destination view controller refers to a view controller that is not configured in the storyboard; the project from which this code was executed doesn't use storyboards for anything. BUT WHAT YOU CAN'T, because the segue code will be the same.

Also note that you do not need to modify the destination view controller in any way, form or form. To programmatically create an unwrapping segment (in other words, build the one-sided section shown here):

@implementation RootNavigationController

- (UIStoryboardSegue*)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {
    return [toViewController segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier];
}

      

@end

Now what I have done in my application; here's what someone else did to create a shogyu without using a storyboard (not without a storyboard):

- (void)presentSignupViewController {
    // Storyboard ID
    UIStoryboard *modalStoryboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
    UINavigationController *navController = [modalStoryboard instantiateViewControllerWithIdentifier:@"MySignupViewController"];
    MySignupViewController *controller = [navController viewControllers][0];

    // Configure your custom view controller, e.g. setting delegate
    controller.delegate = self;

    // Show VC
    navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    BlurryModalSegue *segue = [[BlurryModalSegue alloc] initWithIdentifier:@"SignupScene" source:self destination:navController];

    [segue perform];
}

      

The only difference is in the use of perform and prepareForSegue: when using storyboard at all, you have to call your selection selection method (push ... or present ...) in the performForSegue method; however, the transition method for you is called by the execution method.

<iframe width="853" height="480" src="https://www.youtube.com/embed/y8Fu2PEO2zo?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
      

Run codeHide result


-2


source







All Articles