私は数年前から楽しく出荷しているアプリを持っています。 UICollectionViewでRSSフィードを取得します。 cellForItemAtIndexPathメソッドはテキストを設定し、フィードで指定されたリンクから画像を読み込むデータソースメソッドを呼び出します。存在しない場合は、ウェブページデータをロードし、<img>
タグを検索して画像を取得します。画像が見つかると、デリゲートメソッドが呼び出され、画像がセルに追加されます。 (下)UIcollectionView cellForItemAtIndexPathは、iOS 10でのみNullを返します。 iOS 9とiOS 8でうまく動作します
iOS 8および9で動作しているときは、すべてがうれしいですが、iOS 10で実行すると、RSSフィードが最初に読み込まれたときに表示されるセルが画像で更新されますが、スクロールすると画像が追加されず、 cellForItemAtIndexPath。
imageWasLoadedForStoryにreloadItemsAtIndexPathsを追加すると、スクロールバックしてイメージが表示されますが、reloadItemsAtIndexPathsによってパフォーマンスが低下します。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// ...
if (story.thumbnail) {
[imageView setAlpha: 1.0];
imageView.image = story.thumbnail;
UIActivityIndicatorView *lActivity = (UIActivityIndicatorView *) [collectionView viewWithTag: 900];
[lActivity removeFromSuperview];
}else{
[story setDelegate: self];
[story findArticleImageForIndexPath: indexPath];
}
// ...
}
//delegate method. Called when image has been loaded for cell at specified indexpath
- (void) imageWasLoadedForStory: (RSSStory *) story forIndexPath: (NSIndexPath *) indexPath
{
//get cell
CustomCollectionViewCell *customCell = (id) [self.collectionview cellForItemAtIndexPath: indexPath];
NSLog(@"imageWasLoadedForStory row %i section %i and class %@", (int)indexPath.row, (int)indexPath.section, [customCell class]);
//if cell is visible ie: cell is not nil then update imageview
if (customCell) {
UIImageView *imageView = (UIImageView *) [customCell viewWithTag: 300];
imageView.image = story.thumbnail;
UIActivityIndicatorView *lActivity = (UIActivityIndicatorView *) [customCell viewWithTag: 900];
[lActivity removeFromSuperview];
[customCell setNeedsLayout];
[customCell setNeedsDisplay];
}
//[self.collectionview reloadItemsAtIndexPaths: [NSArray arrayWithObject: indexPath]];
}
- (void) findArticleImageForIndexPath: (NSIndexPath *) indexPath
{
//kick off image search
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
self.thumbnail = [self findArticleForStoryForIndexPath:indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
//image set - return
[self.delegate imageWasLoadedForStory: self forIndexPath: indexPath];
});
});
}
まあ、私は狂っていないかもしれません。私はtagプロパティを使って動作させることができました。 cellForItemAtIndexPathに、私は追加しました: [セルsetTag:indexPath.row]; そして、私のデリゲートメソッドで追加されました: CustomCollectionViewCell * customCell =(CustomCollectionViewCell *)[self.collectionview viewWithTag:indexPath.row]; これはすべて機能しますが、これを規制する方法ではないと私は考えています。 –