画像を実装UICollectionView
して表示しようとしています。テーブルビューセルで完全に機能するものを使用していSDWebimage
ますが、使用しようとすると、アクティビティインジケーターがUICollectionviewCell
停止して削除されません。ダウンロードされた画像がない場合は、プレースホルダー画像が配置されます。この問題を引き起こす可能性のある tableviewcell と collectionviewcell の違いは何ですか。
コードは次のとおりです。
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"personImageCell";
PersonCollectionViewCell *cell = (PersonCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
Person *person = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *imgURL=[person.imageurl stringByAppendingString:@"?maxheight=300&maxwidth=400"];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.hidesWhenStopped = YES;
activityIndicator.hidden = NO;
[activityIndicator startAnimating];
activityIndicator.center = CGPointMake(cell.ivPersonImage.frame.size.width /2, cell.ivPersonImage.frame.size.height/2);
[cell.ivPersonImage setImageWithURL:[NSURL URLWithString:imgURL] placeholderImage:nil options:SDWebImageProgressiveDownload success:^(UIImage *image, BOOL cached){
[activityIndicator stopAnimating];[activityIndicator removeFromSuperview];
NSLog(@"activity indicator should be removed");
}failure:^(NSError *error){
[activityIndicator stopAnimating];[activityIndicator removeFromSuperview];
cell.ivPersonImage.image = [UIImage imageNamed:@"placeholder.png"];
}];
[cell.ivPersonImage addSubview:activityIndicator];
return cell;
}
アップデート:
私がする時NSLog(@"activity indicator should be removed %@,activityIndicator);
私はこの出力を得る:
activity indicator should be removed <UIActivityIndicatorView: 0xa520ab0; frame = (65 90; 20 20); hidden = YES; layer = <CALayer: 0xa520b60>>
それUIActivityindicator
は隠されていることを示していますが、まだ画像の上に表示されています