1

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
4

1 に答える 1

-1

私は解決策を見つけました:

ViewControllerはRootViewControllerである必要があるため、次のように変更しました。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

に:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

ViewController *controller = [[ViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
于 2013-01-13T20:50:17.830 に答える