简体   繁体   中英

Displaying Game Center GKMatchmakerViewController dismisses other view

I have a problem when trying to display the GKMatchmakerViewController on my game view.

Normally I create a multiplayer match programmatically by auto-matching 2 opponents, and that works fine.

But when I try to display the standard Game Center Matchmaking view, it dismisses my game view and pushes me back to the menu.

Menu View -> Game View.

I think the problem might be that my menu view acts as my main view and all other views are removed when the Game Center view is displayed (since only one view controller can be shown at the time).

am I setting up my view hierarchy wrong? How should it be done so my Game View wont be dismissed when displaying the Game Center view?

EDIT - updated with code that calls the GKMatchMakerViewController

GameviewController with method that is called when I want to display the Game Center match making controller

  - (void)presentCustomVSBattle {

    ourRandom = arc4random();
    [self setGameState:kGameStateWaitingForMatch];

   AppDelegate * delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;


    [[GCHelper sharedInstance] findCustomMatchWithMinPlayers:2 maxPlayers:2 viewController:delegate.viewController delegate:self];
}

// This method is called in GCHelper.m

 - (void)findCustomMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers viewController:(UIViewController *)viewController delegate:(id<GCHelperDelegate>)theDelegate {

if (!gameCenterAvailable) return;

matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController;
delegate = theDelegate;

if (pendingInvite != nil) {

    [presentingViewController dismissModalViewControllerAnimated:NO];
    GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:pendingInvite] autorelease];
    mmvc.matchmakerDelegate = self;
      [presentingViewController presentViewController:mmvc animated:YES completion:nil];

    self.pendingInvite = nil;
    self.pendingPlayersToInvite = nil;
    } 
else {

        [presentingViewController dismissModalViewControllerAnimated:NO];
        GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
        request.minPlayers = minPlayers;
        request.maxPlayers = maxPlayers;
        request.playersToInvite = pendingPlayersToInvite;

        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
        mmvc.matchmakerDelegate = self;

         [presentingViewController presentViewController:mmvc animated:YES completion:nil];

        self.pendingInvite = nil;
        self.pendingPlayersToInvite = nil;

    }

} 

在您的情况下,dismissView Controller调用看起来不必要,请尝试摆脱它们:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM