【问题标题】:Unwind segues for 2 View Controllers展开 2 个视图控制器的转场
【发布时间】:2014-03-20 08:28:08
【问题描述】:

我在视图控制器上有一个按钮(后退按钮)。到目前为止很简单。 我有 2 个视图控制器,每个控制器都有一个表。 如果用户从任一表中选择一行,它将转到视图控制器并打开后退按钮。 后退按钮需要返回到用户选择行时所在的原始视图控制器。

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

有什么想法吗?

【问题讨论】:

  • 使用 UINavigationController ?
  • 您可以从代码中放松。将您的按钮连接到确定使用和展开哪个 unwindSegue 的操作
  • Voker,我可以将我的按钮连接到一个动作,如果变量中有“1”,则转到此展开,如果有“2”,则转到此展开。我还在每个我正在展开的 VC 中添加了展开代码。但是我将如何连接到代码中的展开?我无法将开关拖到 VC 上的 EXIT 按钮并同时选择 UNWIND ,我只能选择一个 UNWIND。
  • @user3437628 您可以通过编程方式展开,例如 [self performSegueWithIdentifier:YourUnwindIdentifierHere sender:nil];
  • 感谢沃尔克,它有效。

标签: ios iphone objective-c


【解决方案1】:

正如沃尔克所解释的,

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 2012-09-21
    • 2017-07-17
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2016-07-06
    相关资源
    最近更新 更多