![](/img/trans.png)
[英]How do you receive a game center invite when GKMatchmakerViewController is open?
[英]Displaying Game Center GKMatchmakerViewController dismisses other view
嘗試在游戲視圖上顯示GKMatchmakerViewController時遇到問題。
通常,我會以編程方式通過自動匹配2個對手來創建多人游戲,效果很好。
但是,當我嘗試顯示標准的“游戲中心對接會”視圖時,它將關閉我的游戲視圖,並將我推回菜單。
菜單視圖->游戲視圖。
我認為問題可能是我的菜單視圖充當了我的主視圖,而顯示“游戲中心”視圖時卻刪除了所有其他視圖(因為此時只能顯示一個視圖控制器)。
我的視圖層次結構設置錯誤嗎? 在顯示“游戲中心”視圖時,應該如何做才能使我的“游戲視圖”不被關閉?
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;
}
}
在您的情況下,dismissView Controller調用看起來不必要,請嘗試擺脫它們:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.