在我的应用程序中,我使用了自定义单元格。其中有许多字段,例如按钮、图像、文本字段、标签。
其中我需要显示 indexpath.section
和 indexpath.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/