gpt4 book ai didi

objective-c - Game Center调用排行榜功能没有响应?

转载 作者:行者123 更新时间:2023-11-28 22:58:03 24 4
gpt4 key购买 nike

我这样调用排行榜:

-(void)viewscores:(SPEvent*)event
{

GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil) {
leaderboardController.leaderboardDelegate = self;

UIWindow* window = [UIApplication sharedApplication].keyWindow;
[window addSubview: self.rootViewController];
[self presentModalViewController: leaderboardController animated: YES];

}
}

当我点击排行榜按钮时,我收到一个错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIViewController presentModalViewController:animated:]: unrecognized selector sent to class 0x3e2fc7f8'

这正常吗?

最佳答案

您可能应该在 viewController 中调用该函数。在我的一个应用程序中,代码如下所示:

-(IBAction)showLeaderBoard {

GKLeaderboardViewController *leaderBoardCont = [[GKLeaderboardViewController alloc] init];
if (leaderBoardCont) {
leaderBoardCont.category=@"1S";
leaderBoardCont.timeScope=GKLeaderboardTimeScopeWeek;
leaderBoardCont.leaderboardDelegate=self;
[self presentModalViewController:leaderBoardCont animated:YES];
}

然后你还应该实现委托(delegate)方法:

-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController {

[self dismissModalViewControllerAnimated:YES];
viewController = nil;
}

这里的 1S 是您在 iTunes Connect 中创建的排行榜的标识符。希望这会有所帮助。

编辑:由于您仍然遇到问题,请查看这些教程。它们涵盖了有关排行榜和成就的所有内容。

1st part

2nd part

关于objective-c - Game Center调用排行榜功能没有响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10422805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com