Ios 如何在推送之前关闭模型视图控制器?

Ios 如何在推送之前关闭模型视图控制器?,ios,objective-c,model-view-controller,Ios,Objective C,Model View Controller,现在我的场景是这样的, View Controller(VC1) --> Push Segue --> View Controller(VC2) | ^ | Model Segue | | | Push Segue |--

现在我的场景是这样的,

View Controller(VC1)  -->  Push Segue --> View Controller(VC2)
          |                                   ^ 
          | Model Segue                       |
          |                                   | Push Segue
          |-----> View Controller(VC3)  ------|         
现在在
VC3
中,当我按下
VC2
时,我想退出
VC3
查看控制器和 在
VC2
back按钮后打开,它应该是
VC1的
backview控制器,我想弹出VC3

我想要的是,当我们返回时,当我从VC3中推VC2时,我想要移除VC3,然后它应该出现VC1

我已经这样做了,有人能帮我吗

视图控制器(VC3)

- (void)callWebservice {

   [self dismissViewControllerAnimated:YES completion:^{

         [self performSegueWithIdentifier:@"showVC2" sender:self];
   }];

}

提前感谢

如果您正在使用segue,请尝试以下手动操作:

你可以试试这个

 // locally store the navigation controller since
 // self.navigationController will be nil once we are popped
 UINavigationController *navController = self.navigationController;

 // retain ourselves so that the controller will still exist once it's popped off
 [[self retain] autorelease];

 // Pop this controller and replace with another
 [navController popViewControllerAnimated:NO];//not to see pop

 [navController pushViewController:aViewController animated:YES];
//to see push or u can change it to not to see.
或者试试这个

UIViewController *newVC = [[UIViewController alloc] init]; // Replace the current view controller 
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
[viewControllers removeLastObject]; 
[viewControllers addObject:newVC]; 
[[self navigationController] setViewControllers:viewControllers animated:YES];

如果您正在使用segue,我想您正在寻找,要手动执行此操作,请尝试以下操作:

你可以试试这个

 // locally store the navigation controller since
 // self.navigationController will be nil once we are popped
 UINavigationController *navController = self.navigationController;

 // retain ourselves so that the controller will still exist once it's popped off
 [[self retain] autorelease];

 // Pop this controller and replace with another
 [navController popViewControllerAnimated:NO];//not to see pop

 [navController pushViewController:aViewController animated:YES];
//to see push or u can change it to not to see.
或者试试这个

UIViewController *newVC = [[UIViewController alloc] init]; // Replace the current view controller 
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
[viewControllers removeLastObject]; 
[viewControllers addObject:newVC]; 
[[self navigationController] setViewControllers:viewControllers animated:YES];

我认为您可以通过这种方式实施:

  • 当您在屏幕3时,您需要按下屏幕2。您将退出屏幕3,并将代表调回屏幕1
  • 从屏幕1将视图推到屏幕2
您可以查看我的想法演示:


我认为您可以通过这种方式实现:

  • 当您在屏幕3时,您需要按下屏幕2。您将退出屏幕3,并将代表调回屏幕1
  • 从屏幕1将视图推到屏幕2
您可以查看我的想法演示:



我认为这不会起作用,因为看到我做的这件事了吗?我没有告诉你,我必须在哪里做这件事?我认为在你的callWebservice方法调用中。删除当前代码并放置任何一个选项。您是否遇到任何错误或其他问题?您可以共享更多代码摘录吗?让我们一起分享。我认为这将不起作用,因为看到我做的事情我没有理解您,我必须这样做吗?我认为在您的callWebservice方法调用中。删除当前代码并放置其中任何一个选项。您是否遇到任何错误或其他问题?您可以再分享一些代码摘录吗?让我们分享一下。我认为我们没有其他选项。@CongTran我想弹出VC3,然后在我想推到VC2后,我不明白这个问题。。上面的代码将执行您想要的操作。。别生气it@Daij-Djan我想要的是,当我从VC3中推出VC2时,我想删除VC3。当我们返回时,它应该出现VC1。我认为我们没有其他选择。@CongTran我想推出VC3,然后在我想推出VC2后,我不明白这个问题。。上面的代码将执行您想要的操作。。别生气it@Daij-Djan我想要的是,当我把VC2从VC3上推下来的时候,我想要移除VC3,当我们回来的时候,它应该出现VC1,你在目标C中可以做什么?@BlackCop,没问题。等我一下,我会用Objective-c给你演示。是的,我可以看到,但我的场景与你不同,请检查demo@BlackCop啊,我明白了。你想要推。在这种情况下,我修改了代码。检查它。它正在工作,但有一个问题,当我们从VC3推到vc2时,然后一点timt VC1显示如何隐藏这个问题?你能在目标C中做吗?@BlackCop,没问题。等我一下,我会用Objective-c给你演示。是的,我可以看到,但我的场景与你不同,请检查demo@BlackCop啊,我明白了。你想要推。在这种情况下,我修改了代码。检查它。它在工作,但有一个问题,当我们要从VC3推到vc2,然后一点timt VC1显示如何隐藏这个问题?