放松2个视图控制器的segues [英] Unwind segues for 2 View Controllers

查看:99
本文介绍了放松2个视图控制器的segues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图控制器上有一个按钮(后退按钮)。到目前为止简单。
我有2个视图控制器,每个都有一个表。
如果用户从任一表中选择一行,则会在返回按钮的情况下进入视图控制器。
后退按钮需要返回到用户选择行时所在的原始视图控制器。

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.

我正在考虑为此解开细分,这很好,但我不能在一个按钮上添加两个segue。一个用于返回到一个表视图,另一个用于返回另一个表视图,具体取决于它们用于访问视图控制器的表视图。

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.

任何想法?

推荐答案

正如沃尔克解释的那样,

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] "
    */
    }

请注意,确实如此你还必须在你的segueForUnwindingToViewController:override中使用specialWord,它将位于DESTINATION(也就是说ORIGINAL)视图控制器下面,也就是说。

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];
    }

这篇关于放松2个视图控制器的segues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆