0

最近、「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;

私が間違っていることを教えてください。アプリケーションがクラッシュするため、autorelease を使用できないことはわかっています。

4

1 に答える 1

2

ARC を使用していない場合は、autorelease を追加してください:

cell = [[[ConditionReportCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease] ;
于 2013-06-13T11:03:41.990 に答える