user689805
user689805

Reputation: 53

Calling presentModalViewController just after dismissModalViewControllerAnimated has problems

I have the code

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
    [menuViewController dismissModalViewControllerAnimated:YES];
    [GameKitWrapper getSingleton].match = match;
    match.delegate = [GameKitWrapper getSingleton].remotePlayer;
    [menuViewController presentModalViewController:avatarSelectionViewController
                                      animated:YES];
}

But I have the problem that the dismiss is working but not the present. When I changed dismissModalViewControllerAnimated:YES to dismissModalViewControllerAnimated:NO it worked but does not look nice.

Any help is appreciated.

Upvotes: 4

Views: 5619

Answers (3)

matusz
matusz

Reputation: 1

Try calling:

[menuViewController dismissModalViewControllerAnimated:NO];

before calling:

[menuViewController presentModalViewController:avatarSelectionViewController
                    animated:YES];

Upvotes: -1

Rob Napier
Rob Napier

Reputation: 299663

@adam has the right idea, but you don't want to wait for some arbitrary delay. That's fragile because it might take any amount of time for the animation to complete. You want to wait for the previous view controller to actually finish dismissing. The best place in my experience to put this is in your current view controller's viewDidAppear:. That will be called after your modal has completely gone away. See this question for some example code addressing a similar problem.

Upvotes: 5

adam
adam

Reputation: 22597

Try waiting for a second....

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
    [menuViewController dismissModalViewControllerAnimated:YES];
    [GameKitWrapper getSingleton].match = match;
    match.delegate = [GameKitWrapper getSingleton].remotePlayer;
    [self performSelector:@selector(presentModal) withObject:nil afterDelay:1.0];
}

- (void)presentModal {   
    [menuViewController presentModalViewController:avatarSelectionViewController
                                          animated:YES];
}

Upvotes: 0

Related Questions