Unwind segues for 2 View Controllers

后端 未结 1 1945
遇见更好的自我
遇见更好的自我 2020-12-20 08:06

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

相关标签:
1条回答
  • 2020-12-20 08:21

    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];
        }
    
    0 讨论(0)
提交回复
热议问题