1
votes

I have one button (back button) on a view controller. Simple so far. I have 2 view controllers with a table on each one. if a user selects a row from either table it goes to the view controller with the back button on. The back button needs to go back to the original view controller that the user was on when they selected the row.

I was considering unwind segues for this which is fine, but I cannot add two segues to one button. One for return to one table view and a return for the other table view dependent on which table view they used to access the view controller.

Any ideas ?

1
Use a UINavigationController ?rdurand
you can unwind from code. connect your button to an action that determines which unwindSegue to use and unwindVolker
Voker, I can connect my button to a action and if there is a '1' in a variable go to this unwind and if there is a '2' go to this unwind. I have also added the unwind code in each VC I am unwinding too. but how would i connect to an unwind in code ? I cannot drag the switch to the EXIT button on the VC and select both UNWINDS , I can only select one UNWIND.Jason_Hough
@user3437628 you can unwind programmatically, like [self performSegueWithIdentifier:YourUnwindIdentifierHere sender:nil];Volker
thanks Volker, it works.Jason_Hough

1 Answers

4
votes

As Volk explained,

-(IBAction)devDismiss
    {
    NSLog(@" ------- dev dismiss .....");

    // for a custom segue unwind, you must do this...
    [self performSegueWithIdentifier:@"specialWord" sender:self];

    // "specialWord" is the identifier set on storyboard for the
    // custom unwind segue

    /* for a "default" unwind segue, do this...
    [self dismissViewControllerAnimated:YES completion:nil];
    Note, if you used a push segue, you should use
      [self.navigationController popViewControllerAnimated:YES]
    If you used a modal segue, you should use
      [self dismissViewControllerAnimated:YES completion:nil] "
    */
    }

Note that indeed, you must also use "specialWord" in your segueForUnwindingToViewController: override, which will be in the DESTINATION (that is to say the ORIGINAL) view controller, the one underneath, that is to say.

-(UIStoryboardSegue *)segueForUnwindingToViewController:
                          (UIViewController *)toViewController 
              fromViewController:(UIViewController *)fromViewController 
              identifier:(NSString *)identifier
    {
    NSLog(@"we're in _your class name_, segueForUnwindingToViewController %@",
      identifier);

    // for some unwinds, we have a custom unwind we want to use.
    // so, check the identifier:
    if ([identifier isEqualToString:@"specialWord"])
        {
        YourCustomUnwindSegue *sg = [[YourCustomUnwindSegue alloc] 
                           initWithIdentifier:identifier 
                           source:fromViewController 
                           destination:toViewController];
        return sg;
        }

    // don't forget the break-away "return" inside any macthes.

    // NSLog(@"note, if this message appears, it's likely you have a typo
    //  somewhere for 'specialWord' - unless you genuinely have a situation
    //  where it will also fall through to the 'default' unwind segue :O ");

    // BE SURE TO return the default unwind segue otherwise
    return [super segueForUnwindingToViewController:toViewController 
                                 fromViewController:fromViewController
                                         identifier:identifier];
    }