PFQueryTableViewController带来重复的结果 - 分页

时间:2014-05-16 23:56:33

标签: ios objective-c uitableview pagination parse-platform

我正在使用PFQueryTableViewController从我的Parse数据库中检索一些对象。我正在使用分页来提高我的应用程序的性能。但是,当我要求加载更多对象时,queryForTable会再次执行并再次带来相同的结果。

你们知道这是一个错误还是我能做的事情。

这是我的代码:

- (PFQuery *)queryForTable
{
    NSLog(@"To aqui %@",self.location.name);
    PFQuery *imageQuery = [PFQuery queryWithClassName:@"WallImageObject"];
    [imageQuery whereKey:@"geoPoint" nearGeoPoint:self.location.coordinatesInGeoPoint withinKilometers:0.5];
    [imageQuery whereKey:@"venueName" equalTo:self.location.name];
    [imageQuery orderByDescending:@"createdAt"];

     // If Pull To Refresh is enabled, query against the network by default.
     if (self.pullToRefreshEnabled) {
         imageQuery.cachePolicy = kPFCachePolicyNetworkOnly;
     }

     // If no objects are loaded in memory, we look to the cache first to fill the table
     // and then subsequently do a query against the network.
     if (self.objects.count == 0) {
         imageQuery.cachePolicy = kPFCachePolicyCacheThenNetwork;
     }

     return imageQuery;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{   
    static NSString *CellIdentifier = @"Cell";
    FeedPhotoCell *cell = (FeedPhotoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    NSString *facebbokUserID = object[@"UserId"];
    NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=100&height=100",facebbokUserID];
    NSURL *facebookProfilePicURL = [NSURL URLWithString:urlString];

    [cell.profilePhoto setImageWithURL:facebookProfilePicURL];
    cell.profilePhoto.layer.cornerRadius = 10.0;
    cell.profilePhoto.layer.borderColor = [UIColor colorWithRed:235.0/255.0 green:80.0/255.0 blue:80.0/255.0 alpha:1.0].CGColor;
    cell.profilePhoto.layer.borderWidth = 1.0;
    cell.profilePhoto.clipsToBounds = YES;

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

    return cell;
 }

PS:我做了一些进一步的测试,发现这个问题只有在我尝试[imageQuery whereKey:@"geoPoint" nearGeoPoint:self.location.coordinatesInGeoPoint withinKilometers:0.5];

时才会发生

此致

2 个答案:

答案 0 :(得分:0)

我能想象的唯一一件事就是当你调用时 imageQuery.cachePolicy = kPFCachePolicyCacheThenNetwork; 查询正在填充缓存中的结果,然后当您加载下一页时,它会填充来自网络的结果,这些结果是第二次复制

答案 1 :(得分:0)

我相信你现在可能已经想到了这一点,但是你确实意识到你选择的cellForRowAtIndexPath方法(至少对于你这里的代码而言)是UITableView而不是PFQueryTableViewController。我相信这是所有与解析相关的功能所需要的,并且需要刷新。