2015-12-03 35 views
0

我加入遊戲中心功能,我的應用程序,我遇到了一些奇怪的事情,我不能避開我的頭......GameCenter的報告得分 - 本地聲明隱藏實例變量

我用這個確切的方法(和代碼)在5場比賽,所以我不明白爲什麼它現在拋出一個警告信息...

我得到2x「局部聲明的'分數'隱藏實例變量」在ReportScore方法。 ...

Warnings

的代碼如下:

-(void)reportScore{ 
    GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier]; 
    score.value = gameScore; //gameScore is games Score that needs submitting 

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

我已經試過聲明這樣的變量在.h

@property (nonatomic) GKScore *score; 

但是,引入了一個autosynthesised警告,而不是...我不明白爲什麼當它不在我的任何其他應用程序中這樣做時發生這種情況?

回答

0

我不能相信我這樣做......這表明它是多麼容易錯過當你在代碼這麼長時間盯着的東西...

事實證明,我有與A UIImageView命名score ...

.h 
IBOutlet UIImageView *score; 

簡單地改變GKScore變量名,警告消失......

-(void)reportScore{ 
    GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier]; 
    this_score.value = gameScore; 

    [GKScore reportScores:@[this_score] withCompletionHandler:^(NSError *error) { 
     if (error != nil) { 
      NSLog(@"%@", [error localizedDescription]); 
     } 
    }]; 
    NSLog(@"Reported to Game Center..."); 
} 

什麼甜甜圈!

相關問題