Game Center のターンベースのマッチ、三目並べゲームを行うチュートリアルに従っていますが、View Controller がロードされていません。ソースコードを使用すると機能しますが、本から自分で入力したコードでは機能しません。私はチェックしましたが、違いは見つかりませんでした。
私はGame Centerに入り、「Play your turn」をクリックすると、元のコードのように「tictactoeGameViewController」ではなく、「Begin game」ボタンを含む初期画面が読み込まれます。
誰かがここで私を助けることができれば、私は非常に感謝しています:-)
これが私のコードです:
#import "ViewController.h"
#import "tictactoeGameViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)beginGame:(id)sender {
GKMatchRequest *match = [[GKMatchRequest alloc]init];
[match setMaxPlayers:2];
[match setMinPlayers:2];
GKTurnBasedMatchmakerViewController *tmvc = nil;
tmvc = [[GKTurnBasedMatchmakerViewController alloc]initWithMatchRequest:match];
[tmvc setTurnBasedMatchmakerDelegate:self];
[self presentModalViewController:tmvc animated:YES];
[tmvc release];
[match release];
}
- (void)viewDidLoad {
[super viewDidLoad];
if ([GameCenterManager isGameCenterAvailable]) {
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(localUserAuthenticationChanged:) name:GKPlayerAuthenticationDidChangeNotificationName object:nil];
gcManager = [[GameCenterManager alloc]init];
[gcManager setDelegate:self];
[gcManager authenticateLocalUser];
}
}
-(void)processGameCenterAuthentication:(NSError *)error {
if (error != nil) {
NSLog(@"An error occured during authentication: %@", [error localizedDescription]);
}
}
-(void)localUserAuthenticationChanged:(NSNotification *)notif {
NSLog(@"Authentication Changed: %@", notif.object);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - GCTurnBasedMatchHelperDelegate
-(void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match {
[self dismissModalViewControllerAnimated:YES];
tictactoeGameViewController *gameVC = [[tictactoeGameViewController alloc]init];
gameVC.match = match;
[[self navigationController]pushViewController:gameVC animated:YES];
[gameVC release];
}
-(void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController playerQuitForMatch:(GKTurnBasedMatch *)match {
[match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:^(NSError *error) {
if (error) {
NSLog(@"An error occured ending match: %@", [error localizedDescription]);
}
}];
}
-(void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFailWithError:(NSError *)error {
NSLog(@"Turned Based Matchmaker Failed with Error: %@", [error localizedDescription]);
}
-(void)turnBasedMatchmakerViewControllerWasCancelled:(GKTurnBasedMatchmakerViewController *)viewController {
[self dismissModalViewControllerAnimated:YES];
}
@end