loadAchievementDescriptionsWithCompletionHandler,NSMutableDictionary始终为null

时间:2012-07-16 03:25:59

标签: null game-center nsmutabledictionary gamekit achievements

我已经尝试了几个小时而且我无法使用它,在我的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");
}

我为此疯狂,任何帮助都会很棒。感谢。

1 个答案:

答案 0 :(得分:0)

自我来自self.achievementsDescDictionary

可能是个问题

在.h

中使用
@property (retain) NSMutableDictionary* achievementsDescDictionary;

在.m

@synthesize achievementsDescDictionary;
...
achievementsDescDictionary = [[NSMutableDictionary alloc] init];