1
インターネットからダウンロードした画像を含むセルをテーブルビューに読み込もうとしています。私はすぐにユーザーがスクロールダウンすると、すべての画像をダウンロードするのではなく、現在表示されているセルでダウンロード操作を実行したいと思います。テーブルビューの可視行のみに画像を設定する
私はこの中にはstackoverflowのを閲覧見つかりましたが、それはあまり役に立ちません。この
インターネットからダウンロードした画像を含むセルをテーブルビューに読み込もうとしています。私はすぐにユーザーがスクロールダウンすると、すべての画像をダウンロードするのではなく、現在表示されているセルでダウンロード操作を実行したいと思います。テーブルビューの可視行のみに画像を設定する
私はこの中にはstackoverflowのを閲覧見つかりましたが、それはあまり役に立ちません。この
を実施するための最良の方法です
- (void)configureVisibleCellsForTableView:(UITableView *)tableView animated:(BOOL)animated {
[self tableView:tableView configureRowsAtIndexPaths:tableView.indexPathsForVisibleRows animated:animated];
}
- (void)tableView:(UITableView *)tableView configureRowsAtIndexPaths:(NSArray *)indexPaths animated:(BOOL)animated {
for (NSIndexPath *indexPath in indexPaths) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell) {
[self tableView:tableView configureCell:cell forRowAtIndexPath:indexPath animated:animated];
}
}
}
- (void)tableView:(UITableView *)tableView configureCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated {
// Cell configuration
}
何私は最善の方法は、のためにカスタムクラスを設定することだと思いますこれはセル画の前に呼び出される - forRowAtIndexPath :?:willDisplayCell:あなたはのtableView見(_をとっているセルとprepareForReuseをオーバーライドして、ダウンロードが私の場合は
override func prepareForReuse() {
super.prepareForReuse()
// cancel downloading of the imageView
}
ようImageViewのにrefrencedキャンセルhttps://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:willDisplayCell:forRowAtIndexPathに記載されているように、 – Daven