0

ARC を使用していますが、カスタムの UITableCellView がリリースされていないようです。

TBMListingLineView は、UITableCellView のサブクラスである TBMGlobalCustomCell のサブクラスです。

TBMListingLineView には 10 個の UILabels (非アトミック、保持) があります。

両方のクラスに、決して呼び出されないメソッド dealloc を実装しました (ブレークポイントは実行を停止しません)。

TableView をスクロールしているときに、Instruments/Allocations で UILabel の数が増加しているため、いくつかのメモリ警告の後でアプリケーションがクラッシュしました。

ここに画像の説明を入力

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

static NSString *CellIdentifier = @"Cell";

TBMGlobalCustomCell* cell;

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

switch(sortIndex) {
    case 0 :
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil || ![cell isKindOfClass:[TBMListingLineView class]]) {
            cell = [[TBMListingLineView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }

    break;

....

return cell;

}

4

1 に答える 1

2

dequeueReusableCellWithIdentifier最初の問題は、セルごとに 2 回呼び出すことです。次に、2 番目にデキューされたセルに適切なクラスがない場合も、そのセルを「破棄」します。

より良い解決策は、テーブル ビューで使用されるセル (サブ) クラスごとに異なるセル識別子を使用することdequeueReusableCellWithIdentifierです。これにより、正しいクラスのインスタンスが返されます。

于 2013-08-16T20:42:58.020 に答える