0

I continue refining the implementation of my UICollectionViewController with Parse and this time I'm dealing with an issue that it might be related to cache or maybe the reloadData method itself.

Maybe you can help me identify the source of this strange behavior that I better show you on a short video to save time:

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];

}

Then on my refreshControlAction:

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

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

    [refreshControl endRefreshing];
}

The query method is like this:

- (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]);
        }
    }];
}

This doesn't happen on my PFQueryTableViewController where I'm performing the exact same query and where I'm also using the iOS 6 refresh control instead of the one provided by Parse.

Do you see something that could be causing this behavior?

4

1 回答 1

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`

另一个问题是我不知道您是否在查询完成时更新了数据源。

于 2013-10-25T01:25:04.163 回答