PFQueryTableViewController 带来重复的结果 - 分页

Posted

技术标签:

【中文标题】PFQueryTableViewController 带来重复的结果 - 分页【英文标题】:PFQueryTableViewController bringing duplicate results - Pagination 【发布时间】:2014-05-16 23:56:33 【问题描述】:

我正在使用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];时才会出现

问候

【问题讨论】:

我也有同样的问题。您能分享一下您的解决方案吗? 【参考方案1】:

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

【讨论】:

【参考方案2】:

我相信您现在可能已经弄清楚了,但您确实意识到您选择的 cellForRowAtIndexPath 方法(至少对于您的代码而言)是用于 UITableView 而不是 PFQueryTableViewController。我相信所有像这样的解析相关功能都需要这样做并拉动刷新。

【讨论】:

以上是关于PFQueryTableViewController 带来重复的结果 - 分页的主要内容,如果未能解决你的问题,请参考以下文章