我可以毫无问题地加载排行榜。但是当点击“完成”按钮时,我无法关闭它。
我如何打开它:
- (IBAction)leaderboardsClickedid)sender{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
[self presentViewController:leaderboardController animated:YES completion:NULL];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Error"
message: @"You must be logged into Game Center to view the leaderboards. Open Game Center?"
delegate: self
cancelButtonTitle"No"
otherButtonTitles"Yes",nil];
[alert show];
}
}
我是如何关闭它的:
- (void)gameCenterViewControllerDidFinishGKGameCenterViewController *)gameCenterViewController{
NSLog(@"test");
[self dismissViewControllerAnimated:YES completion:nil];
}
编辑:
该方法根本没有运行;所以“测试”甚至不会被打印出来。
我将 添加到我的 ViewController 的协议(protocol)中。
Best Answer-推荐答案 strong>
试试这个:
- (IBAction)leaderboardsClickedid)sender{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
leaderboardController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
[self presentViewController:leaderboardController animated:YES completion:NULL];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Error"
message: @"You must be logged into Game Center to view the leaderboards. Open Game Center?"
delegate: self
cancelButtonTitle"No"
otherButtonTitles"Yes",nil];
[alert show];
}
}
还有:
- (void) gameCenterViewControllerDidFinishGKGameCenterViewController*) gameCenterViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
关于ios - 无法关闭 Game Center 排行榜页面,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/25577584/
|