Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 设置游戏中心排行榜,使其';这是柜台_Ios_Objective C_Game Center_Game Center Leaderboard - Fatal编程技术网

Ios 设置游戏中心排行榜,使其';这是柜台

Ios 设置游戏中心排行榜,使其';这是柜台,ios,objective-c,game-center,game-center-leaderboard,Ios,Objective C,Game Center,Game Center Leaderboard,是否可以设置游戏中心排行榜,以便“得分”保持不变?我想用排行榜来显示一个玩家的赢数,但我不知道怎么可能用排行榜来增加计数器,是吗?您可以使用NSUserDefaults来保存和检索数据(赢数) 例如: //ViewController.h : NSInteger NbrOfWins ; //ViewController.m : - (void)viewDidLoad { //... [super viewDidLoad]; // ... //Retrieving data N

是否可以设置游戏中心排行榜,以便“得分”保持不变?我想用排行榜来显示一个玩家的赢数,但我不知道怎么可能用排行榜来增加计数器,是吗?

您可以使用NSUserDefaults来保存和检索数据(赢数)
例如:

//ViewController.h :    
NSInteger NbrOfWins ; 




//ViewController.m :
- (void)viewDidLoad
{
//...
[super viewDidLoad];
// ...

//Retrieving data
NbrOfWins = [[NSUserDefaults standardUserDefaults] integerForKey:@"Wins"];

}




-(void)NewWin{
//...

NbrOfWins = NbrOfWins + 1 ;

//Saving data
[[NSUserDefaults standardUserDefaults]setInteger:NbrOfWins forKey:@"Wins"];

//Calling a Game Center function to send the new number of wins :
[self reportScore];
}



//Game center functions 
-(void)reportScore{
// Create a GKScore object to assign the score and report it as a NSArray object.
GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier];

//Sending the new number of wins :
score.value = NbrOfWins;

[GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) {
    if (error != nil) {
        NSLog(@"%@", [error localizedDescription]);
    }
  }];
}

// ... Other game center functions please see the documentation
有关游戏中心实施的更多信息:


有关NSUserDefaults的更多信息:

谢谢,但我正在使用Parse.com,所以保存wins不是问题,问题是如何让GC将其显示为wins表,因为如果您只提交wins数,它将保持一个新分数,但我需要的是保持一个分数,并不断更新它。@Phil你说GC是什么意思?@Phil你想在GC中显示什么?仅赢的次数或其他信息?赢的次数。但很明显,这需要一个持久值,换句话说,它不能是每次提交的新数字,它需要是一个更新后的数字,然后游戏中心显示它们。我不知道问题出在哪里?与前面的代码:例如,如果你的胜利数是7,那么当你赢了其他时间的数字将更改为8!那么问题出在哪里呢?我们将新编号(旧编号+1)发送给gc,它将更新值:)