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`當查詢完整

另一個問題是我不知道,如果你當查詢完成了數據源更新。