4

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.

user689805
  • 53
  • 1
  • 3

3 Answers3

5

@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.

Community
  • 1
  • 1
Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • 1
    I have an alternative here (http://stackoverflow.com/a/8317603/126855) that doesn't require overriding viewDidAppear:. – Bill Nov 29 '11 at 20:56
0

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];
}
adam
  • 22,404
  • 20
  • 87
  • 119
  • 1
    ya.. dismissing and presenting a UIView controller in the same runloop can cause real UI issues, even crashes (at least in a previous SDK I was using). And Ive often found that its not a guarantee to simply delay presenting the next viewcontroller. Because of this, I simply avoid this design altogether. – Jason Cragun May 01 '11 at 14:25
  • Waiting for a span of time is fragile. If it's too long, the app will be needlessly unresponsive; if it's too short, your present call will fail. I found a solution that doesn't rely on timing here: http://stackoverflow.com/a/8317603/126855 – Bill Nov 29 '11 at 20:56
-1

Try calling:

[menuViewController dismissModalViewControllerAnimated:NO];

before calling:

[menuViewController presentModalViewController:avatarSelectionViewController
                    animated:YES];
Tisho
  • 8,320
  • 6
  • 44
  • 52
matusz
  • 1
  • -1 The asker tried this already, and was opposed to the lack of animations of dismissing the view controller and didn't want it to just disappear. – zachjs Oct 11 '12 at 00:05