2013-07-07 135 views
0

我继续使用Parse来细化我的UICollectionViewController的实现,这次我正在处理一个问题,它可能与缓存或reloadData方法本身有关。使用UICollectionView reloadData刷新控件问题

也许你可以帮我鉴定的这种奇怪的行为的来源,我好给你一个简短的视频,以节省时间:

Refreshing issue video

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    refreshControl = [[UIRefreshControl alloc] init]; 
    [refreshControl addTarget:self action:@selector(refershControlAction) forControlEvents:UIControlEventValueChanged]; 
    [self.collectionView addSubview:refreshControl]; 

    [self queryForTable]; 

} 

然后在我的refreshControlAction:

- (void)refershControlAction 
{ 
    NSLog(@"Reload grid"); 

    // The user just pulled down the collection view. Start loading data.  
    [self queryForTable]; 

    [refreshControl endRefreshing]; 
} 

查询方法是这样的:

- (void)queryForTable 
{ 
    PFQuery *query = [PFQuery queryWithClassName:@"Photo"]; 
    query.limit = 15; 
    [query orderByAscending:@"createdAt"]; 
    [query setCachePolicy:kPFCachePolicyNetworkOnly]; 

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
     if (!error) { 
      // The find succeeded. 
      NSLog(@"Successfully retrieved %d photos.", objects.count); 

      [self.collectionView reloadData]; 

      gridImages = [[NSMutableArray alloc] initWithCapacity:objects.count]; 

      // Do something with the found objects 
      for (PFObject *object in objects) { 

       PFFile *thumbnail = [object objectForKey:@"thumbnail"]; 
       [thumbnail getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
        if (!error) { 
         // Now that the data is fetched, update the cell's image property with thumbnail 

         //NSLog(@"Fetching image.."); 

         [gridImages addObject:[UIImage imageWithData:data]]; 

         //NSLog(@"Size of the gridImages array: %d", [gridImages count]); 

        } else { 
         // Log details of the failure 
         NSLog(@"Error: %@ %@", error, [error userInfo]); 
        } 
       }]; 
      } 
     } else { 
      // Log details of the failure 
      NSLog(@"Error: %@ %@", error, [error userInfo]); 
     } 
    }]; 
} 

这不会发生在我的PFQueryTableViewController,我正在执行完全相同的查询,我也在使用iOS 6刷新控件而不是Parse提供的那个。

您是否看到可能导致此行为的内容?

+0

哪里是你的数据源,你会得到它更新? – babygau

回答

0

我可以在你的代码中看到一些概率。

- (void)refershControlAction 
{ 
NSLog(@"Reload grid"); 

// The user just pulled down the collection view. Start loading data.  
[self queryForTable]; 

[refreshControl endRefreshing]; 
} 

endRefreshing查询之前得到完成,所以这是错误的使用。你应该把[refreshControl endRefreshing] in your - (VOI)queryForTable`当查询完整

另一个问题是我不知道,如果你当查询完成了数据源更新。