Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在解析时从缓存加载UITableView数据_Ios_Objective C_Uitableview_Caching_Parse Platform - Fatal编程技术网

Ios 在解析时从缓存加载UITableView数据

Ios 在解析时从缓存加载UITableView数据,ios,objective-c,uitableview,caching,parse-platform,Ios,Objective C,Uitableview,Caching,Parse Platform,正如您在下面看到的,我有一个嵌套查询,即使我使用或我认为我使用了解析缓存,加载它也需要3-4秒。它不像我预期的那样工作。是否有可能在第一次启动时从缓存加载,然后从解析云进行更新。我是否至少需要核心数据或sqlite3来同步本地端的解析 另外,当我使用query.cachePolicy tableview获得重复的结果时,我如何以正确的方式使用它 - (void) retrieveSnapsFromParse { NSString *currentUserName = [PFUser curre

正如您在下面看到的,我有一个嵌套查询,即使我使用或我认为我使用了解析缓存,加载它也需要3-4秒。它不像我预期的那样工作。是否有可能在第一次启动时从缓存加载,然后从解析云进行更新。我是否至少需要核心数据或sqlite3来同步本地端的解析

另外,当我使用query.cachePolicy tableview获得重复的结果时,我如何以正确的方式使用它

- (void) retrieveSnapsFromParse {

NSString *currentUserName = [PFUser currentUser].username;

PFQuery *retrieveSnaps = [PFQuery queryWithClassName:@"Snap"];
[retrieveSnaps whereKey:@"from" equalTo:[PFUser currentUser].username];

PFQuery *retrieveSnaps2 = [PFQuery queryWithClassName:@"Snap"];
[retrieveSnaps2 whereKey:@"to" equalTo:[PFUser currentUser].username];

PFQuery * query = [PFQuery orQueryWithSubqueries:@[retrieveSnaps, retrieveSnaps2]];
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
[query orderByDescending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
    for (PFObject *object in objects) {

            Snap *snap = [Snap new];

     if([currentUserName isEqualToString:[object objectForKey:@"to"]]) {
                snap.userName = [object objectForKey:@"from"];
                snap.sentOrReceived = @"Received";

                PFFile *snapImageFile = [object objectForKey:@"snappedimage"];
                [snapImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
                    if (!error) {
                        UIImage *snapImage = [UIImage imageWithData:data];
                        snap.snapImage = snapImage;
                    }
                }];

            } else if([currentUserName isEqualToString:[object objectForKey:@"from"]]) {
                snap.userName = [object objectForKey:@"to"];
                snap.sentOrReceived = @"Sent";

            }


            snap.opened = [object[@"opened"]boolValue];
            snap.counter = [object[@"second"]intValue];
            snap.objectId = [NSString stringWithFormat:@"%@",object.objectId];

            NSDate *createdAt = object.createdAt;
            snap.createdDate = createdAt;

    // Profile image for UICustomTableViewCell
      PFQuery *userQuery = [PFUser query];
            [userQuery whereKey:@"username" equalTo:snap.userName];
             userQuery.cachePolicy = kPFCachePolicyCacheElseNetwork;
            [userQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
                if (object) {
                    snap.userFirstName = [object objectForKey:@"firstname"];
                    PFFile *imageFile = [object objectForKey:@"profileimage"];
                    [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
                        if (!error) {
                            UIImage *image = [UIImage imageWithData:data];
                            snap.userProfileImage = image;

                        }

                    }];

                    [snapsTemp addObject:snap];
                }

        snapsTable = snapsTemp;
                    [self.tableView reloadData];

            }];
     }
    }
}];
}

我在下面CellForRowatineXpath上使用的代码

cell.cellUserProfileImage.image = snap.userProfileImage;
也在.m文件中用于可变数组

    @implementation SnapsVC
{
    NSMutableArray *snapsTable;
}

在我将下面的代码放入CellForRowatineXpath而不是retrieveSnapsFromParse之后,它开始像我预期的那样工作

PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"username" equalTo:snap.userName];
userQuery.cachePolicy = kPFCachePolicyCacheElseNetwork;
[userQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    if (object) {

        PFFile *imageFile = [object objectForKey:@"profileimage"];
        [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
            if (!error) {
                cell.cellUserProfileImage.image = [UIImage imageWithData:data];
            }

        }];

        cell.cellUserFirstNameLabel.text = [object objectForKey:@"firstname"];
    }
}];