インターネットからダウンロードした一連のアイコンを読み込むサンプルUICollectionViewを使用してアプリケーションを開発しています。したがって、基本的にサーバーはJSONファイル内の各アイコンのURLを含むリストを取得し、解析して各セルが対応するイメージをダウンロードします。UICollectionViewセル画像エラー
このアプローチの問題は、画像のダウンロード中にユーザーがスクロールを開始すると、間違った順序で画像が表示されてしまうことです。それはUICollectionViewが '私を助けよう'としているようなもので、間違った場所にあるコンテンツをレンダリングします!
私はこれについて多くのスレッドを見てきましたが、私は彼らの提案のほとんどを試しましたが、これまでのところ多くの運がありませんでした。誰かがこのような何かを見た?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
PeqImage *image = [self.responseIcons objectAtIndex:indexPath.row];
PeqCustomCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"PeqCustomCell" forIndexPath:indexPath];
cell.peqImage = image;
cell.imageName = [NSString stringWithFormat:@"%@.png",image.assetId];
NSString *theImageUrl = [NSString stringWithFormat:@"http://www.XXXX.com/pb/images/uncompressed/%ld.png",(long)indexPath.row];
[cell downloadImage:[NSURL URLWithString:theImageUrl]];
return cell;
}
そして、これは、ダウンロードアルゴリズムは、(UIImageView + AFNetworkingを使用して)どのように見えるかです::
- (void) downloadImageWithUrl:(NSURL*) url completion:(PeqCustomCellCompletionBlock)completionBlock
{UIImage *placeholder = [UIImage imageNamed:@"placeholder"];
NSURLRequest *jpegURLRequest = [NSURLRequest requestWithURL:url];
self.imageUrl = url.absoluteString;
[self.imageView setImageWithURLRequest:jpegURLRequest
placeholderImage:placeholder
success:^(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *image) {
image = [self normalizeImage:image];
completionBlock(image);
}
failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {
NSLog(@"Error downloading image from network");
}];
cellForItemAtIndexPathがどのように見えるか
です
}
この回答ありがとうございます。私はトリックをやった!私は別のライブラリ (UIImageView + AFNetworking)を使用していましたが、SDWebImageの方が遅いようですが、画像をダウンロードする方法で動作します! –