PresentViewController dismiss 不会返回到上一个 viewController

PresentViewController dismiss doesn`t go back to previous viewController

在我的项目中,我们有三个 windows A、B 和 C。我想从 A 推送视图 B,从 B 我想呈现视图 C。 我的代码: ViewController答:

ViewControllerB *vcB = [[viewControllerB alloc] 
initWithNibName:@"ViewControllerB" bundle:nil];
[[self navigationController] pushViewController:vcB animated:YES];

视图控制器 B:

ViewControllerC *vcC = [[ViewControllerC alloc] 
initWithNibName:@"ViewControllerC" bundle:nil];
[self presentViewController:vcC animated: true completion: nil];

到目前为止一切正常,但是当我关闭最后一个视图控制器时:

[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];

应用返回到第一个视图控制器 (vcA) 而不是第二个视图控制器 (vcB)

我做错了什么? 谢谢大家。

试试这个来关闭 vc

[self dismissViewControllerAnimated:NO completion:nil]

并用它弹出

 [self.navigationController popToViewController:controller animated:YES];

[self presentingViewController] = Bvc ,所以在这里你实际上解雇了 B 而不是 C

 [Bvc dismissViewControllerAnimated:NO completion:nil];

但是 self = Cvc 所以这里你只解雇了 C

 [self dismissViewControllerAnimated:NO completion:nil];

您一定是在做一些您没有告诉我们的其他事情...

这按预期工作:

MyFirstViewController.m

- (IBAction)pushTapped:(id)sender {
    MyPushedViewController *vc = [[MyPushedViewController alloc] initWithNibName:@"MyPushedViewController" bundle:nil];
    [self.navigationController pushViewController:vc animated:YES];
}

MyPushedViewController.m

- (IBAction)presentTapped:(id)sender {
    MyPresentedViewController *vc = [[MyPresentedViewController alloc] initWithNibName:@"MyPresentedViewController" bundle:nil];
    [self presentViewController:vc animated:YES completion:nil];
}

MyPresentedViewController.m

- (IBAction)dismissTapped:(id)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}

点击 MyPresentedViewController 中的 "dismiss" 按钮关闭显示的视图控制器(您的 vcC),让我留在 MyPushedViewController(您的 vcB)。 .. NOTMyFirstViewController(你的 vcA)。