【发布时间】:2013-06-13 10:59:16
【问题描述】:
我最近切换到“不使用 XIB 进行编程”,但遇到了自定义 TableView 单元格的问题。以前在使用XIB时,我使用了以下代码,效果很好,
NSString *CellIdentifier = @"Cell";
AttachmentCustomCell *cell=(AttachmentCustomCell*)[self.attachmenttableview dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
NSArray* objects= [[NSBundle mainBundle] loadNibNamed:@"AttachmentCustomCell" owner:nil options:nil];
AttachmentCustomCell *acell = [objects objectAtIndex:0];
cell = acell;
}
但现在我正在使用以下内容,这给了我内存泄漏,
static NSString *CellIdentifier = @"Cell";
ConditionReportCustomCell *cell = (ConditionReportCustomCell*)[self.inventoryTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
cell = [[ConditionReportCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
return cell;
请告诉我我做错了什么。我知道我不能使用自动释放,因为它会导致应用程序崩溃。
【问题讨论】:
-
在 Pro 中使用 ARC 吗?
-
对不起,我忘了提。我没有使用 ARC
标签: ios memory-leaks xcode4.5 autorelease