1

これを行うと、はるかに高速に動作するようです:

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    JHomeViewCell *cell = (JHomeViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[JHomeViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:CellIdentifier];

        cell.cellContent.thumbnailCache = self.thumbnailCache;
    }

    Entry *entry = [self.resultsController objectAtIndexPath:indexPath];
    if (cell.cellContent.entry != entry) {
        [cell.cellContent setNeedsDisplay];
    }
}

問題は、エントリが編集されたときにセルが変更されないことです。セルのすべての要素をチェックして、それらが異なるかどうかを確認できますが、これを行うより良い方法はありますか? セルが表示されるたびに drawrect を呼び出すと、アプリの速度が低下し、不要に見えます。

4

1 に答える 1

1

テーブルビュー セルのカスタム描画を行いたい場合は、サブクラス化する必要がありますUITableViewCell(で行ったようにJHomeViewCell)。

JHomeViewCell の実装内に drawRect を配置します。

@implementation JHomeviewCell

- (void)drawRect:(CGRect)rect
{
    [super drawRect];
    // Insert drawing code here
}

@end

また、drawRect を直接呼び出さないでください。代わりに呼び出すsetNeedsDisplay必要があり、おそらく cellContent.entry 値を結果コントローラーから取得したエントリに設定する必要があります。

Entry *entry = [self.resultsController objectAtIndexPath:indexPath];
if (cell.cellContent.entry != entry) {
    cell.cellContent.entry = entry;
    [cell setNeedsDisplay];
}
于 2012-04-29T15:08:00.050 に答える