【发布时间】:2011-11-24 15:52:17
【问题描述】:
我在 TableViewCell 中有 UIImage 插座,稍后我将在 UITableView 中使用它。当我在仪器中检查这个时,我在 UIImageView 上发现了一些内存泄漏。我没有在 UITableViewCell 中释放 UIImageView,因为如果我在 tavleViewCell 中释放它,我会得到 exc_bad_access。
我的问题是我在哪里发布这个 UIImageView?
更新
CustomCell.h
@interface CustomCell : UITableViewCell {
IBOutlet UIImageView *customImage;
}
@property(nonatomic, retain) UIImageView *customImage;
@end
CustomViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.customImage.hidden = [[self.customImageList objectAtIndex:indexPath.row] boolValue];
return cell;
}
【问题讨论】:
-
据我了解,您使用的是 UITableViewCell 子类。您应该对它的代码进行 pst,包括接口定义。
-
您应该在 cell 的 dealloc 中释放 cell 拥有的对象。该版本不应出现异常。如果您遇到异常,则代码中的保留/释放平衡有问题。
标签: objective-c cocoa-touch uitableview uiimageview