从 UINavigationController 放松到 UIViewController

Unwind from UINavigationController to UIViewController

我有一个 MYViewController,它使用

等自定义转场预设了 MYNavigationController
- (void)perform
{
    [self.sourceViewController presentViewController:self.destinationViewController animated:NO completion:nil];
}

我还有一个 unwind segue,比如

- (void)perform
{
    [self.sourceViewController dismissViewControllerAnimated:NO completion:nil];
}

在 Storyboard 中,MYNavigationController 和 Navigation Controller Scene 中的 Exit 占位符之间存在联系 – 带有标识符 unwindToVC1 的 unwind segue。

MYNavigationController 看起来像这样

...

- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier 
{
    MYCustomUnwindSegue *segue = [[MYCustomUnwindSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController];

    return segue;
}

- (IBAction)unwindToVC1:(UIStoryboardSegue *)sender
{
}

- (IBAction)dissmissMYNavigationController:(id)sender
{
    [self performSegueWithIdentifier:@"unwindToVC1" sender:sender];
}

...

所以当我调用 -dissmissMYNavigationController 时什么也没有发生。甚至 -segueForUnwindingToViewController:fromViewController:identifier: 都没有被调用。

我做错了什么?谢谢!

如果您想从导航器控制器中删除顶部 ViewController,您必须调用 popViewControllerAnimated:dismissViewControllerAnimated 用于呈现模态 ViewController.

我好像不太清楚展开是如何工作的,所以

- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier 
{
    MYCustomUnwindSegue *segue = [[MYCustomUnwindSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController];

    return segue;
}

- (IBAction)unwindToVC1:(UIStoryboardSegue *)sender
{
}

应该在MYViewController,而不是在MYNavigationController