私は画像を解析してダウンロードしています。その後、その画像をuicollectionビューで表示していますが、コレクションビューをスクロールするとハングします。ここに私のコードparseから画像をダウンロードし、UICollectionビューで表示する
-(void)viewWillAppear:(BOOL)animated
{
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat height = CGRectGetHeight(screen);
PFQuery * query = [PFQuery queryWithClassName:@"Static_Wallpaper"];
[query selectKeys:@[@"thumbnail"]];
if (height == 480) {
[query selectKeys:@[@"image4s"]];
}
else{
[query selectKeys:@[@"image6s"]];
}
[query findObjectsInBackgroundWithBlock:^(NSArray * objects, NSError * error){
if (!error) {
[imgArry arrayByAddingObjectsFromArray:objects];
imgArry = [[NSMutableArray alloc] initWithArray:objects];
NSLog(@"%lu",(unsigned long)imgArry.count);
[cllectionView reloadData];
}
}];
}
である。ここでコレクションビューで画像を取り込むコードである
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return imgArry.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
PFObject *imageObject = [imgArry objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:@"image4s"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error){
NSLog(@"is there any data? %@", data);
cell.imgView.image = [UIImage imageWithData:data];
;
}
else {
NSLog(@"no data!");
}
}];
return cell;
}
別のイメージに置き換えられたセル内のコレクションビューイメージをスクロールすると、1つの問題が発生する – salmancs43