データモデルを使用して、ビデオ、画像の 2 つのオブジェクトを格納します。ビデオには文字列属性のみが含まれ、画像には 2 つの「バイナリ データ」属性があります。
最初は、2 つのバイナリ データ属性がビデオ オブジェクトにありました。ただし、UITableView の初期化中にすべてのビデオが読み込まれます。400 本のビデオの場合、バイナリ データは 20 Mo を表すため、4000 本のビデオを想像してみてください...
2 つのオブジェクトを使用すると、UITableView の読み込みがうまく機能します。メソッドで必要な場合は、バイナリ データを読み込みます: tableView:cellForRowAtIndexPath
しかし、リストをスクロールすると、メモリが増えます:(
私の方法を見てください:
- (UITableViewCell *)tableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"videoCell";
Video *theVideo = (Video *)[[self fetchedResultsController] objectAtIndexPath:indexPath];
VideoCellViewController *cell = (VideoCellViewController *)[myTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"VideoCellView" owner:self options:nil];
cell = editingTableViewCell;
self.editingTableViewCell = nil;
}
cell.video = theVideo;
return cell;
}
そして、VideoCellViewController の setvideo メソッド
- (void)setVideo:(Video *)newVideo {
if (newVideo != video) {
[video release];
video = [newVideo retain];
}
NSData *imageData = [video.allImages valueForKey:@"thumbnailImage"];
UIImage *uiImage = [[UIImage alloc] initWithData:imageData];
smallImage.image = uiImage;
nameLabel.text = video.displayName;
[uiImage release];
}
smallImage を設定しなくても、メモリに問題があります。画像オブジェクトをロードすると、決して解放されません。
私は成功せずにメモリを解放するために多くの解決策を試みます...( didTurnIntoFault、release、CFRelease...) パフォーマンス ツールでは、バイナリ データが CFData として表示されます。
iPhoneCoreDataRecipes と PhotoLocations のサンプルをよく使用します。
記憶をきれいにするために助けが必要です;)
ありがとう
サミュエル