Search code examples
iossegueuistoryboarduistoryboardsegue

Can you read the storyboard segue identifier in the receiving view


I've used storyboard to create a segue between scene 1 and scene 2. Scene one has a view controller with multiple buttons where each button represents a particular action to perform within the view controller of scene 2. I have individually control-dragged between each button on the scene 1 view controller to create an action segue to the view controller in scene 2. I then created a unique segue identifier for each of these segue actions. So the question is this -> Is it possible for the view controller in scene2 (say in viewDidLoad()) to determine what the segue identifier is that is causing the segue?

I'm already familiar with the use of performSegueWithIdentifier:sender to pass data between view controllers, but since storyboard already enables the segue to occur without writing code when the button is pressed, I was hoping that the segue identifier is available at the receiving view controller. So again, Is it possible for the view controller in scene2 (say in viewDidLoad()) to determine what the segue identifier is that is causing the segue?


Solution

  • I guess you are looking for the below method

    • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { DestinationViewController *dvc = segue.destinationViewController; dvc.segueIdentifier = segue.identifier; if ([segue.identifier isEqualToString:@"Button 1"]) { // } }