尝试在游戏视图中显示GKMatchmakerViewController时遇到问题。
通常情况下,我通过自动匹配2个对手以编程方式创建多人游戏匹配,并且工作正常。
但是当我尝试显示标准的Game Center Matchmaking视图时,它会取消我的游戏视图并将我推回菜单。
菜单视图 - >游戏视图。
我认为问题可能是我的菜单视图充当我的主视图,并且在显示游戏中心视图时删除了所有其他视图(因为当时只能显示一个视图控制器)。
我是否设置了我的视图层次结构错误?怎么做才能让我的游戏视图在显示游戏中心视图时不被解雇?
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];
}
//在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;
}
}
答案 0 :(得分:1)
在你的情况下,dismissView控制器调用看起来没必要,试着去掉它们:)