0

なぜARCを有効にしてメモリをリークしていますか(太字で強調表示)?ARCを有効にしたカスタムセルのメモリリーク

私はCustomCell.m

私のテーブルビューのconterollerで
+(CustomCell*)cell 
{ 


    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     NSArray *nib =[[NSBundle mainBundle] loadNibNamed:@"CustomCell_iPhone" owner:self options:nil];   
     return [nib objectAtIndex:0]; 

    } else { 
     NSArray *nib =[[NSBundle mainBundle] loadNibNamed:@"CustomCell_iPad" owner:self options:nil];   **//leaking 100%** 
     return [nib objectAtIndex:0]; 

    } 
} 

持っている:だから

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell=[CustomCell cell]; **// 100% leaking** 
... 
} 

答えて

1

、二つのことを。 1つは、このセルを.xibファイルで作成することです。 IBのセルに再使用識別子を設定します。その後、代わりにこのCustomCellクラスメソッドの、のtableViewにペン先をアンロード:cellForRowAtIndexPathが:,次のように:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Assuming you set a reuse identifier "cellId" in the nib for your table view cell... 
    MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:@"cellId"]; 
    if (!cell) { 
     // If you didn't get a valid cell reference back, unload a cell from the nib 
     NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:nil options:nil]; 
     for (id obj in nibArray) { 
      if ([obj isMemberOfClass:[MyCell class]]) { 
       // Assign cell to obj, and add a target action for the checkmark 
       cell = (MyCell *)obj; 
       break; 
      } 
     } 
    } 

    return cell; 
} 

2つ目は最初の再利用可能なセルをデキューしようとすることで、あなたがはるかに良いパフォーマンスを得るということです。

関連する問題