简体   繁体   English

显示游戏中心GKMatchmakerViewController关闭其他视图

[英]Displaying Game Center GKMatchmakerViewController dismisses other view

I have a problem when trying to display the GKMatchmakerViewController on my game view. 尝试在游戏视图上显示GKMatchmakerViewController时遇到问题。

Normally I create a multiplayer match programmatically by auto-matching 2 opponents, and that works fine. 通常,我会以编程方式通过自动匹配2个对手来创建多人游戏,效果很好。

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 编辑-使用调用GKMatchMakerViewController的代码进行更新

GameviewController with method that is called when I want to display the Game Center match making controller GameviewController具有当我想显示Game Center配对控制器时调用的方法

  - (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 //在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调用看起来不必要,请尝试摆脱它们:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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