ios - 从解析查询中保存 PFObjects

标签 ios nsmutablearray parse-platform pfquery

我想将来自 Parse 查询的 PFObjects 保存在我的类称为 listdata 的 NSMutableArray 中。我稍后会使用 listdata 数组。当我跟踪我的代码时,它会为找到的每个对象更新 highScoreObjects 数组。但是当我尝试将 listdata 数组设置为 highScoreObjects 数组时,highScoreObjects 数组为空。有没有办法在查询结束后保留​​数据?

NSMutableArray *highScoreObjects = [[NSMutableArray alloc] initWithCapacity:5];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // The find succeeded.
            NSLog(@"Successfully retrieved %d scores.", objects.count);
            // Do something with the found objects
            for (PFObject *object in objects) {
                [highScoreObjects addObject:object];
                NSLog(@"%@", object.objectId);
            }
            dispatch_async(dispatch_get_main_queue(), ^ {
                [self.tableView reloadData];
            });
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];

self.listData = highScoreObjects;

我还尝试保留行 self.listData = highScoreObjects;self.listData = highScoreObjects; 循环中。这没有任何区别。

最佳答案

不是没有设置。只是还没有。这是因为您正在使用 findObjectsInBackgroundWithBlock 并且异步过程尚未完成。

将您的分配 (self.listData = highScoreObjects;) 移动到 block 中,就在您发送重新加载 TableView 的请求之前。

关于ios - 从解析查询中保存 PFObjects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20081481/

相关文章:

iphone - 如果表格从 3 种类型的自定义单元格加载,如何计算单元格的高度?

ios - 获取设置为 ON 的开关数量

如果重写 UIView 中的drawRect,IOS 单元测试会抛出异常

ios - UIPickerView 选择更新 UITextFields 的 NSArray

iphone - 如何将CGContextAddArc(CGContextRef)中的所有点存储到NSMUtableArray

ios - 将自定义对象添加到 NSMutablearray 不起作用,添加对象返回空数组

iphone - 关于 NSData 的不明确信息 - Objective C/Xcode

ios - PF ImageView 不适用于 PF CollectionViewCell 的子类

ios - 如何使用回调在 Swift 中进行异步调用,以便主 UI 不会挂起?

javascript - 使用基于服务器变量的javascript更改div的值