简体   繁体   English

iOS无法解析PFFile和PFObjects上的查询

[英]iOS parse query on PFFile and PFObjects not fetching in order

I'm not really sure if it's my code, or if it's parse not fetching the query correctly. 我不太确定这是我的代码,还是解析后无法正确获取查询。 I have a "Photo" class table filled with PFFiles that are photos, and each photo has a corresponding caption of string type. 我有一个“照片”类表,其中充满了作为照片的PFFiles,并且每张照片都有相应的字符串类型标题。 When I query the table/class, the captions fetch in correct descending order, but rarely do the photos. 当我查询表/类时,标题以正确的降序获取,但是很少拍照片。 As a result the photos don't have the correct corresponding captions (strings). 因此,照片没有正确的相应标题(字符串)。 I used the getDataInBackgroundWithBlock method for the PFFile because I was getting the notorious "there is a long running parse operation" warning with out it. 我对PFFile使用了getDataInBackgroundWithBlock方法,因为我得到了臭名昭著的“存在长时间运行的解析操作”警告,但没有警告。 HELP! 救命! Here is my code: 这是我的代码:

- (void)queryParse
{
    PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
    [query orderByDescending:@"createdAt"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

        if (!error) {
            for (PFObject *object in objects) {

                [objectIDArray addObject:object.objectId];
                NSString *postedBy = object[@"postedBy"];
                [postedByFeedArray addObject:postedBy];
                NSString *caption = object[@"caption"];
                [captionFeedArray addObject:caption];

                PFFile *file = object[@"photoFile"];
                [file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
                     if (!error) {
                         [photoFeedArray addObject:data];
                     }
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [_activityIndicator stopAnimating];
                        [_tableView reloadData];
                    });
                }];

            }
        } else {
            NSLog(@"ERROR: %@", error);
        }
    }];
}

Unwrap PFFiles. 解包PFFiles。

    func loadData() {
    var findUser = PFUser.query()
    findUser.whereKey("username", equalTo: profileUser.username)
    findUser.getFirstObjectInBackgroundWithBlock { (object:PFObject!, error: NSError!) -> Void in
        if (error == nil) {
            if let profileImage:PFFile = object["profileImage"] as? PFFile {
                profileImage.getDataInBackgroundWithBlock({ (imageData:NSData!, error: NSError!) -> Void in
                    if (error == nil) {
                        let image:UIImage = UIImage(data: imageData)!
                        self.profileImageView.image = image
                    }
                    else{
                        println(error)
                        self.presentErrorMessage(error)
                    }
                })
            }

        }
        else {
            // Log details of the failure
            println(error)
            self.presentErrorMessage(error)
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM