passol
passol

Reputation: 195

blank when presentViewController after dimissViewController immediately

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?

Upvotes: 0

Views: 582

Answers (4)

user3017305
user3017305

Reputation:

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"];

Upvotes: 0

Wang Yandong
Wang Yandong

Reputation: 136

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];

Upvotes: 0

arundevma
arundevma

Reputation: 933

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];

Upvotes: 0

rdelmar
rdelmar

Reputation: 104092

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];

Upvotes: 1

Related Questions