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
是否确定关注本指南http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Achievements/Achievements.html – Omarj