我有一个与这个非常相似的问题
基本上我正在使用 Parse.com 加载一些具有 PFUser 指针的对象,然后我还使用 includeKey 来包含那些 PFUser,这是代码...
PFQuery *query = [PFQuery queryWithClassName:@"GameVillageObject"];
[query whereKey:@"region" equalTo:[NSNumber numberWithInt:region]];
[query includeKey:@"pfUser"];
query.limit = 100;
[sharedInstance requestSentWithDesc:@"Get all village objects in region"];
[query findObjectsInBackgroundWithBlock:^(NSArray *PUObjects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d village objects from server.", PUObjects.count);
if(PUObjects.count > 0)
{
villageObjects = PUObjects;
for (int i=0; i<[villageObjects count]; i++)
{
PFObject *villageItem = [villageObjects objectAtIndex:i];
PFUser *user = [villageItem objectForKey:@"pfUser"];
NSString *userName = [NSString stringWithFormat:@"%@",[user objectForKey:@"username"]];
NSLog(@"User name is: %@.", userName);
}
[self setupVillageList];
[sharedInstance centerImage:marketItemsContainer xChoice:YES yChoice:NO];
}
} else {
// Log details of the failure
NSLog(@"Getting village objects Error: %@ %@", error, [error userInfo]);
}
}];
现在由于某种原因,一次又一次,也许 10 次中有 1 次,游戏崩溃,出现这个错误
键“用户名”没有数据。在获取其值之前调用 fetchIfNeeded。
虽然我不知道当我尝试使用上面的“用户名”时它是否会崩溃,或者稍后当我尝试使用“用户名”时,但无论哪种方式,我都不明白为什么大多数时候它都没有问题,包括那些额外的对象,然后几次它没有。有任何想法吗?