アプリでコアデータを使用してNSFetchedResultsController
、テーブルにデータを入力しています。私のデータベースには 40,000 以上のエントリがあるため、テーブルはかなり長くなります。各テーブル セルには、SDWebImageを使用して Web から読み込まれたサムネイル イメージがあります。ゆっくりスクロールするとすべてうまくいきますが、数秒以内に速くスクロールし始めるとクラッシュします。
NSZombies は有用なものを何も表示していません。
私はそれがSDWebImage
Webからの読み込みに関係していると推測しています。その方法SDWebImage
は、画像をバックグラウンドでロードし、ダウンロードが完了した後にダウンロードした画像を設定することです (wordy)。私の考えでは、セルがによって割り当て解除され、割り当て解除されたUITableView
セルSDWebImage
に画像を設定しようとしています。そのため、いつ割り当てが解除されるかを判断できれば、ダウンロード プロセスをUITableViewCell
停止して問題を解決できます。SDWebImage
追加してみました
- (void)dealloc {
NSLog(@"dealloc");
}
セルの割り当てが解除されるタイミングをキャッチしますが、何も得られません。
EDIT-(void)dealloc
サブクラス UITableViewCell
にメソッドがあります。
編集 ここにセルを作成する場所/方法があります
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* inventoryCellID = @"InventoryCustomCellID";
InventoryCustomCell* cell = (InventoryCustomCell *)[tableView dequeueReusableCellWithIdentifier:inventoryCellID forIndexPath:indexPath];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(InventoryCustomCell *)cell atIndexPath:(NSIndexPath *)indexPath {
[cell formatCellWithProduct:[fetchedResultsController objectAtIndexPath:indexPath] enableAdding:NO];
cell.openThumbnailButton.tag = indexPath.row;
[cell.openThumbnailButton addTarget:self action:@selector(presentThumbnailViewWithCell:) forControlEvents:UIControlEventTouchUpInside];
}
私のカスタムセルでは、これは呼び出されている構成メソッドです:
- (void)formatCellWithProduct:(Product*)product enableAdding:(bool)addingEnabled {
self.titleLabel.text = product.part_number;
self.partNumberLabel.text = [[[product.manufacturer allObjects] objectAtIndex:0] name];
//The SDWebImage UIImageView category method
[self.thumbImageView setImageWithURL:[NSURL URLWithString:product.photo] placeholderImage:[UIImage imageNamed:@"icon.png"]];
}
編集 画像をダウンロードして設定するSDWebImageメソッドは次のとおりです。
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock;
{
[self cancelCurrentImageLoad];
self.image = placeholder;
if (url)
{
__weak UIImageView *wself = self;
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
{
__strong UIImageView *sself = wself;
if (!sself) return;
if (image)
{
sself.image = image;
[sself setNeedsLayout];
}
if (completedBlock && finished)
{
completedBlock(image, error, cacheType);
}
}];
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}