カスタム ビュー (HorizontalMenuView) を使用するビュー コントローラー (EmbeddedMenuView) があります。埋め込みメニュー ビューは、複数の HorizontalMenuViews を使用します。HorizontalMenuView には UITableView が含まれています。テーブル ビューの各セルはかなりの量のメモリを使用します (高品質の画像)。
今度は、HorizontalMenuView のテーブル ビュー セルのセクションがタッチされるたびに、タスクを実行する必要があります。これを行うには、テーブル ビュー セルにプロトコルを作成し、HorizontalMenuView にそのデリゲートを割り当てます。次に、HorizontalMenuView でプロトコルを作成し、EmbeddedMenuView にデリゲートを割り当てました。そこで、タッチ イベントを EmbeddedMenuView に渡します。
問題は、セルのデリゲートを割り当てると、HorizontalMenuView の割り当てが解除されないことです。このビューはビューが表示されるたびに更新されるため、メモリ使用量はすぐに制御不能になります。
セルにデリゲートが割り当てられている部分をコメントアウトすると、すべて正常に機能します。
私の質問は: UITableViewCell のデリゲートを適切に解放するにはどうすればよいですか?
これは、HorizontalMenuView のコード スニペットです。
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Custom Logic
HorizontalMenuItemTableViewCell *cell = (HorizontalMenuItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[NSClassFromString([[AMPUIManager sharedManager] classNameForName:cellIdentifier]) alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
cell.shouldAlwaysTransform = shouldAlwaysTransform;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.colorsDict = colorsDict;
if ([cell isKindOfClass:[ATCustomTableViewCell class]]) {
((ATCustomTableViewCell *)cell).delegate = self; //Commenting this out solves my problem.
}
}
//More Custom Logic
return cell;
}
PS私は手動参照カウントを使用しています。ARC は、このプロジェクトのオプションではありません。