UITableView自定义单元格中单元格重用的问题

时间:2013-05-11 17:08:07

标签: ios objective-c uitableview custom-cell

在我的应用程序中,我使用了自定义单元格。在其中我有许多字段,如按钮,图像,文本字段,标签。

其中我需要显示indexpath.sectionindexpath.row

我试过

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

但由于重用机制,显示的值有些时间错误。

如何解决此问题?

1 个答案:

答案 0 :(得分:1)

也许你可以分享其他一些代码。

与此同时(这是传统方式)

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