0

I have a A viewController ,first, I present B viewController,after some work, I need to dismiss B viewController and present C viewController , so I use the following code in the A viewController:

        UIViewController *gp = self.presentedViewController;
        [gp dismissModalViewControllerAnimated:NO];
        [self presentModalViewController:viewController animated:YES];

it works But I encountered a problem , when B viewController is dismissed ,the user always can see the A viewController, then the C viewController is presented.I want to avoid this issue to directly to C viewController directly! So what can I do?

passol
  • 195
  • 4
  • 12
  • BTW, it makes no sense to have gp dismiss itself, because it just forwards that message back to its presentingViewController, which is A. Also, you shouldn't be using the depreciated present and dismiss methods. – rdelmar Nov 25 '13 at 06:04

4 Answers4

1

If you want to go directly to C, just do that. Have B present C, and don't dismiss B. If you want to go directly back to A from C, you can use this:

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
rdelmar
  • 103,982
  • 12
  • 207
  • 218
0

Try This Kind of Code.Dismiss using UIStoryBoard. create an identifier for your view controller and Dont forget to write the identifier name of the view controller

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:NULL]; ViewControllerC *viewControllerc = [storyboardinstantiateViewControllerWithIdentifier:@"identifier name"];

0

Instead of using present view controller add view as child view controller. ie First add view B as child view controller and its view as subview. Then add C and remove B.

ViewControllerB *b= [ViewControllerB alloc]initWith.......;
ViewControllerC *c= [ViewControllerB alloc]initWith.......;
[self addChildViewController:b];
[self.view addSubview:b.view];
[self addChildViewController:c];
[self.view addSubview:c.view];
[b.view removeFromSuperview];
[b removeFromParentViewController];
arundevma
  • 933
  • 7
  • 24
0

Actually you don't need to dismiss B, just present C within B. And dismiss view controller within A when the work is done.

[_a presentViewController:_b animated:YES completion:nil];
[_b presentViewController:_c animated:YES completion:nil];

// When the work is done with C, just ask A to dismiss the view controller
[_a dismissViewControllerAnimated:YES completion:nil];
Wang Yandong
  • 136
  • 3