3

我有一个导航控制器 A,我在其上推送视图控制器 B。我从 B 模态地呈现视图控制器 C。我需要同时关闭 C 和弹出 B。我想按顺序进行,首先保持关闭动画,然后是从 B 到 A 的弹出动画。我尝试了这段代码但没有成功:

[self dismissViewControllerAnimated:YES completion:^{
       [self.presentingViewController.navigationController popViewControllerAnimated:YES];
}];

关于如何实现这一目标的任何建议?

4

3 回答 3

1

我之前曾尝试连续弹出两次,但没有关闭一次并弹出另一次。你可以试试我做的,看看它是否适合你。

在子视图 B 中:

- (void)subViewCController:(SubViewCController *)controller didSelectID:(NSNumber *)theID
{
    // do something with theID...
    // for my case, I popped
    // [self.navigationController popViewControllerAnimated:YES];

    // for your case
    [self dismissViewControllerAnimated:YES completion:nil];

    // Somehow, adding a small delay works for me and the animation is just nice
    [self performSelector:@selector(backToSubViewA) withObject:nil afterDelay:0.6];
}

- (void)backToSubViewA
{
    [self.navigationController popViewControllerAnimated:YES];
}
于 2014-10-21T15:09:56.120 回答
1

如果您使用 C viewcontoller 编写,那么:

UIViewController *pvc = self.presentingViewController;
UINavigationController *navController = [pvc isKindOfClass:[UINavigationController class]] ? (UINavigationController *)pvc : pvc.navigationController;
[self dismissViewControllerAnimated:YES completion:^{
  [navController popViewControllerAnimated:YES];
}];

或者如果在 B 视图控制器中

[self.presentedViewController dismissViewControllerAnimated:YES completion:^{
   [self.navigationController popViewControllerAnimated:YES];
}];
于 2014-10-21T14:27:05.750 回答
0

你在使用故事板和转场吗?如果是这样,您可以使用 unwind segue:

在您的第一个视图控制器(您要跳回那个,而不是您要返回的那个中,创建一个 unwind segue 动作:

- (IBAction)gotoMainMenu:(UIStoryboardSegue *)segue
{
    // if you need to do anything when you return to the main menu, do it here
}

然后在情节提要中,您可以创建从“关闭”按钮到在此处输入图像描述场景上方栏中的退出出口图标 ( ) 的转场,您会看到main menu那里列出。

于 2014-10-21T14:28:06.443 回答