PresentViewController dismiss不会回到之前的viewController

时间:2018-01-09 18:12:09

标签: ios objective-c uiviewcontroller pushviewcontroller presentviewcontroller

在我的项目中,我们有三个窗口A,B和C.从A我想推视图B,而从B我想呈现视图C. 我的代码: ViewController A:

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)

我做错了什么? 谢谢你们,伙计们。

3 个答案:

答案 0 :(得分:1)

你必须做一些你没有告诉我们的事情......

这可以按预期工作:

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中的“关闭”按钮会解除显示的视图控制器(您的vcC),让我离开MyPushedViewController(您的vcB)... MyFirstViewController(您的vcA)。

答案 1 :(得分:0)

试试这个以解雇vc

[self dismissViewControllerAnimated:NO completion:nil]

并使用此选项来弹出

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

答案 2 :(得分:0)

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

 [Bvc dismissViewControllerAnimated:NO completion:nil];

但是自我= Cvc所以在这里你只解雇C

 [self dismissViewControllerAnimated:NO completion:nil];