放松2个视图控制器的segues

时间:2014-03-20 08:28:09

标签: ios iphone objective-c

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

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

有什么想法吗?

1 个答案:

答案 0 :(得分:4)

正如沃尔克解释的那样,

-(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)视图控制器中,即下面的控制器,也就是说。

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