UITableViewCell, dequeue and autorelease?

I am sure that what I am doing here is correct, but I just wanted to check that it was [cell autorelease]n’t freeing my cells too early and that it dequeueReusableCellWithIdentifierwas queuing cells around waiting for reuse. My understanding is that a queue is a separate object to the extent that it stores the plan for the cell (a bit like a tip), and not the actual object?

- (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;
}

EDIT: To clarify, I'm interested in what happens in terms of life expectancy and cells. I understand that I distribute them and then automatically check them, then does the table get ownership of the cells after they return from cellForRowAtIndexPath? so they ten belong to a UITableView, or am I embarrassed?

+3
source share
1 answer

No, it actually stores a cell object for each identifier.

, . , , . , , ; .

+2

Source: https://habr.com/ru/post/1779215/


All Articles