这是我的第一个应用程序,包括游戏中心,我有一点问题。 我实现了一些我应该在网上找到的代码。一切正常,除了“完成按钮”:(
的.m
#import <GameKit/GameKit.h>
- (void)viewDidLoad {
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil)
NSLog(@"Authentication Successful!");
else
NSLog(@"Authentication Failed!");
}];
-(IBAction)subscore{
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"lrhseasy"];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil) {
NSLog(@"Submitting a score failed!");
}
else {
NSLog(@"Submitting succeeded!");
}
}];
}
-(IBAction)showLeader{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc]init];
if (leaderboardController != nil) {
//leaderboardController.leaderboardDelegate = self;
[self presentModalViewController:leaderboardController animated:YES];
}
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController {
NSLog(@"Close leaderboard");
[self dismissModalViewControllerAnimated:YES];
[viewController.view.superview removeFromSuperview];
}
当按下完成按钮时,没有调用最后一个函数 - 我没有在调试控制台中获得“关闭排行榜”。
搜索了3个小时后,我发现的唯一一件事就是 “您是否将GKLeaderboardViewControllerDelegate添加到此类实现的协议列表中?”但我不知道这意味着什么或如何完成:(
答案 0 :(得分:2)
我遇到了类似的问题,但要将GKLeaderBoardViewControllerDelegate添加到您的协议列表中,请执行以下操作:
@interface YourClass: NSObject <GKLeaderBoardViewControllerDelegate> {
}
@end