iOS dev
iOS dev

Reputation: 2284

Issues with cell reuse in a UITableView custom cell

In my my app I have used a custom cell. Within it I have many fields like button, image, textfield, label.

Among those I need to display the indexpath.section and indexpath.row values

I tried with

cell.sectionLabel.text = [NSString stringWithFormat:@"%d", indexPath.section];    
cell.rowLabel.text = [NSString stringWithFormat:@"%d", indexPath.section];

but the displayed values are some time wrong due to reuse mechanism.

How to resolve this issue?

Upvotes: 0

Views: 453

Answers (1)

Lorenzo B
Lorenzo B

Reputation: 33428

Maybe you can share some other code.

In the meantime (that's the traditional way)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    //dequeue the cell here...

    if(!cell) {
        //create the cell here...
    }

    cell.sectionLabel.text = [NSString stringWithFormat:@"%d", indexPath.section];
    cell.rowLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; // set row here

    return cell;
}

Upvotes: 1

Related Questions