【发布时间】:2012-10-04 11:33:47
【问题描述】:
我有一个使用界面生成器设计的表格视图的自定义单元格。在它的 .m 文件中,我有一些类似这样的代码,用于从包中获取自定义单元格的 xib。
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"SubItemsCustomCell" owner:self options:nil];
self = [nibArray objectAtIndex:0]; }
return self;
}
然后当我在我的 cellForRowAtIndexPath 方法中使用这个单元格并传递一个自动释放消息时
if (!cellForSubItems) {
cellForSubItems = [[[SubItemsCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SubItemCell"] autorelease];
}
当我滚动 tableView 时它崩溃了,
-[SubItemsCustomCell release]: message sent to deallocated instance 0xed198b0
当我使用代码制作自定义单元格时它从未崩溃,但在这里却发生了,为什么会这样? 此外,当我不自动释放它时,它运行得非常好,但显然它会有内存泄漏。 请帮我解决这个问题。提前致谢。
编辑:我没有使用 ARC。
【问题讨论】:
-
好的,看看我在 cellForRawAtIndexPath: Method.. 中使用 customcell 的另一种方法..]
标签: iphone ios uitableview autorelease