gpt4 book ai didi

iphone - UITableViewCell,出队和自动释放?

转载 作者:搜寻专家 更新时间:2023-10-30 20:23:09 24 4
gpt4 key购买 nike

我很确定我在这里做的是正确的,但我只是想检查 [cell autorelease] 没有过早释放我的单元格以及 dequeueReusableCellWithIdentifier 有排队等待重用的单元格。我的理解是队列是一个独立的实体,因为它存储了单元的蓝图(有点像 Nib )而不是实际的对象?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LOC_ID"];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LOC_ID"];
[cell autorelease];
}
NSUInteger row = [indexPath row];
//id thisLocation = [locationList objectAtIndex:row];
[[cell textLabel] setText:[NSString stringWithFormat:@"R_%u", row]];
return cell;
}

编辑: 澄清一下,我对生命周期和细胞方面发生的事情很感兴趣。我知道我分配它们然后自动释放它们,然后表是否在从 cellForRowAtIndexPath 返回后获取单元格的所有权?所以它们 10 个属于 UITableView,还是我弄糊涂了?

最佳答案

不,它实际上是按标识符存储单元格对象。

当表格第一次创建时,单元格是从头开始创建的。因此,当您滚动 tableview 时,新单元格将根据标识符出队。出于性能原因,可以通过例如在单元格上设置文本来重用它;因此无需从头开始创建新单元格。

关于iphone - UITableViewCell,出队和自动释放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4389720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com