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

时间:2015-12-10 08:58:20

标签: ios objective-c model-view-controller

目前我的情况是这样的,

View Controller(VC1)  -->  Push Segue --> View Controller(VC2)
          |                                   ^ 
          | Model Segue                       |
          |                                   | Push Segue
          |-----> View Controller(VC3)  ------|         

现在VC3当我推进VC2时,我想解雇VC3查看控制器和 在VC2后退按钮之后它应该是VC1's后视图控制器我想要弹出VC3

我想要的是当我从VC3推VC2时我想删除VC3当我们回来它VC1应该出现

Check Example

我这样做过,任何人都可以帮助我

查看控制器(VC3)

- (void)callWebservice {

   [self dismissViewControllerAnimated:YES completion:^{

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

}

提前致谢

2 个答案:

答案 0 :(得分:0)

我认为您正在寻找https://stackoverflow.com/a/21415225/1320305如果您正在使用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];

答案 1 :(得分:0)

我认为你可以这样实现:

  • 当您在屏幕3时,您想要推屏2.您将关闭屏幕3并呼叫代表返回屏幕1.
  • 从screen1开始,您将视图推送到screen2。

您可以看到我的演示文稿:Demo Pushview Swift

DemoPushViewObj