我有一个使用自定义视图(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不是此项目的选项。
答案 0 :(得分:1)
听起来你可能有一个循环引用。您几乎总是希望与委托一起使用“assign”约定。
请参阅:Why are Objective-C delegates usually given the property assign instead of retain?