UITableViewCell
読み取り専用の cell.contentView の代わりに、entryView というプロパティを持つサブクラスがあります。テーブル ビューを正しく使用していると思いました。セルはエントリごとに再利用され、毎回すべてを追加する必要があることを思い出しました。ただし、スクロールすると、セルの entryView が消えることがあります。セルは引き続き存在しますが、entryView はスーパービューから削除されたように見えます。ここに私の cellForRowAtIndexPath があります:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
JTimelineCell *cell = (JTimelineCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[JTimelineCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
JTimelineCellContentView *contentView;
Entry *entry = [_fetchedResultsController objectAtIndexPath:indexPath];
if ([self.cellContentCache objectForKey:entry.entryID]) {
contentView = [self.cellContentCache objectForKey:entry.entryID];
contentView.frame = cell.bounds;
[contentView setNeedsDisplay];
}
else {
contentView = [[JTimelineCellContentView alloc] initWithFrame:cell.bounds];
[self.cellContentCache setObject:contentView forKey:entry.entryID];
contentView.time = [NSDate timeStringForTime:entry.creationDate];
contentView.message = entry.message;
[cell setNeedsDisplay];
}
[cell.entryView removeFromSuperview];
cell.entryView = contentView;
[cell addSubview:cell.entryView];
return cell;
}