使用来自NIB的UITableViewCells进行内存管理?

时间:2011-03-01 17:42:46

标签: iphone objective-c cocoa-touch

通常当我设置UITableViewCell时,我使用默认的cellStyles,根据需要分配和自动释放单元格。我的问题是关于以下示例中的内存管理。分配FGCustomCell在哪里,是否在我要求nib中包含对象时创建它?我也假设自动释放,所以下面的代码很好吗?

- (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 个答案:

答案 0 :(得分:1)

你是对的,FGCustomCell是通过加载nib来分配的,并且是自动释放的。