1

我已经尝试了几个小时,但我无法让它工作,在我的 GameCenterManager 课程中,我得到了这个:

- (void) retrieveAchievmentMetadata {
self.achievementsDescDictionary = [[NSMutableDictionary alloc] init];

[GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:
 ^(NSArray *descriptions, NSError *error) {
     if (error != nil) {
         NSLog(@"Error %@", error);

     } else {
         if (descriptions != nil){
             for (GKAchievementDescription* a in descriptions) {
                 [achievementsDescDictionary setObject: a forKey: a.identifier];
                 NSLog(@"identifier %@", a.identifier);
             }
             NSLog(@"count %i", [achievementsDescDictionary count]);
         }
     }
 }];

}

一切正常,输出很好,计数很好,但是当我尝试调用它以从另一个类获取 GKAchievementDescription 时,它总是返回(null)并且计数为 0。

NSLog(@"count %i", [gameCenterManager.achievementsDescDictionary count]);
if (gameCenterManager.achievementsDescDictionary == NULL) {
    NSLog(@"ERROR");
}

我为此发疯了,任何帮助都会很棒。谢谢。

4

1 回答 1

0

May be a problem with the self from self.achievementsDescDictionary

Use in the .h

@property (retain) NSMutableDictionary* achievementsDescDictionary;

And on the .m

@synthesize achievementsDescDictionary;
...
achievementsDescDictionary = [[NSMutableDictionary alloc] init];
于 2012-09-10T22:24:56.980 回答