【发布时间】:2013-07-07 17:57:47
【问题描述】:
我继续使用 Parse 优化 UICollectionViewController 的实现,这一次我正在处理一个可能与缓存或 reloadData 方法本身有关的问题。
也许您可以帮我找出这种奇怪行为的根源,我最好在短视频中向您展示以节省时间:
- (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 提供的控件。
您是否发现可能导致此行为的原因?
【问题讨论】:
-
你的数据源在哪里,你更新了吗?
标签: ios uicollectionview parse-platform reloaddata uirefreshcontrol