2013-01-12 97 views
1

我正在跟着一個教程做一個遊戲中心基於回合的比賽,井字遊戲,我的視圖控制器沒有加載。它在我使用源代碼的時候起作用,但不能和我從書中輸入的代碼一起使用。我已檢查並找不到任何區別。我的視圖控制器沒有加載遊戲中心

我確實進入了遊戲中心,當我點擊「播放你的回合」時,它會按鈕「開始遊戲」加載初始屏幕,而不是像原始代碼那樣,它假設爲「tictactoeGameViewController」。

我將非常感謝,如果有人可以幫助我在這裏:-)

這裏是我的代碼:

#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 
+0

是否確定關注本指南http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Achievements/Achievements.html – Omarj

回答

-1

我沒有找到解決辦法:

的視圖控制器必須是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; 
} 
相關問題