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

标签 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];

但由于重用机制,显示的值有时会出现错误。

如何解决这个问题?

最佳答案

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

同时(这是传统方式)

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

关于ios - UITableView 自定义单元格中单元格重用的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16499660/

相关文章:

ios - 为什么 Atom 提要不再更新我的 iOS 报亭封面?

iphone - 如何在ios上实现360度展示案例?

ios - 计算 scrollView 中的精确缩放

ios - 如何制作类似于iphone删除动画的摆动动画

ios - Grand Central Dispatch 嵌套队列和不同的队列优先级

项目列表数组上的 PHP/Swift JSON 序列化导致零元素

android - 推送通知 Symfony/Sly notification Pusher 上的 400 错误请求

ios - UIViewContentModeScaleAspectFill 扩展 UIView 的框架

ios - 带有额外空间的 UITableViewController 滚动(如 Notes 应用程序)

ios - uitableview 中的自定义配件不会调用accessorybuttontapped 委托(delegate)