问题
In my ios app lets say I have three ViewControllers
: A
, B
, and C
.
From A
I present B
and assign A
as a delegate. After an action is done on B
I want to then dismiss B
and present C
from A
. However, I want to do this without A
showing up on the screen at all. This is my code right now, inside class A
:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
B *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"B-identifier"];
vc.delegate = self;
[self presentViewController:vc animated:NO completion:^{}];
}
Then this is the delegate function inside A
that B
calls when the action is performed:
- (void) actionPerformed
{
[self dismissViewControllerAnimated:YES completion:^{
C *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"C"];
[self presentViewController:vc animated:NO completion:nil];
}];
However this causes C to show up for a bit (after calling dismiss) even though I put the presenting code in the completion handler of the dismissal. What can I do to avoid that?
回答1:
If you are using it for login approach then you should try a different approach. I mean if A is your rootViewController(make it as login view controller) which check if user has a session or not. suppose user has a session then make your C viewController as rootViewController using [[[[UIApplication sharedApplication] delegate] window]setRootViewController:]
and if he does not has a session show him the same page (A viewController) there is no need of B. Just try it may be it will improve your app performance.
回答2:
You can manage this by timeinterval
like This way
you can first dissmiss the view [self dismiss];
-(void)dismiss
{
[self dismissViewControllerAnimated:YES completion:nil];
[self performSelector:@selector(present) withObject:nil afterDelay:2.0];
}
-(void)present
{
C *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"C"];
[self presentViewController:vc animated:NO completion:nil];
}
来源:https://stackoverflow.com/questions/26381393/ios-present-view-controller-immediately-after-dismissing-a-previous-one