2011-03-01 63 views
0

通常,當我設置UITableViewCell時,我使用默認的cellStyles,根據需要分配和自動釋放單元。我的問題是關於下面例子中的內存管理。 FGCustomCell分配在哪裏,當我要求包含在筆尖中的對象時創建它?我也假設它的autoreleased,所以下面的代碼是好的?使用來自NIB的UITableViewCells進行內存管理?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    FGCustomCell *customCell = (FGCustomCell *)[tableView dequeueReusableCellWithIdentifier:@"FGCELL_ID"]; 
    if(customCell == nil) { 
     NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"FGCustomCell" owner:self options:nil]; 
     for(id eachObject in nibObjects) { 
      if([eachObject isKindOfClass:[FGCustomCell class]]) customCell = (FGCustomCell *)eachObject; 
     } 
    } 
    return customCell; 
} 

回答

1

您是對的,FGCustomCell是由加載的筆尖分配並創建自動釋放。

相關問題