1

尝试在我的游戏视图上显示 GKMatchmakerViewController 时遇到问题。

通常,我通过自动匹配 2 个对手以编程方式创建多人游戏,并且效果很好。

但是当我尝试显示标准的 Game Center Matchmaking 视图时,它会关闭我的游戏视图并将我推回菜单。

菜单视图 -> 游戏视图。

我认为问题可能是我的菜单视图充当我的主视图,并且在显示 Game Center 视图时删除了所有其他视图(因为当时只能显示一个视图控制器)。

我是否设置了我的视图层次结构错误?应该怎么做才能在显示游戏中心视图时不会关闭我的游戏视图?

编辑 - 使用调用 GKMatchMakerViewController 的代码进行更新

GameviewController 与当我想显示游戏中心匹配控制器时调用的方法

  - (void)presentCustomVSBattle {

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

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


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

// 这个方法在 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;

    }

} 
4

1 回答 1

1

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

于 2013-01-15T12:29:41.837 回答