0

我正在使用 UITableView 显示多行数据:textLabel.text 用于名称,imageView 用于显示状态(在线/离线),detailTextLabel 用于附加信息。

前任。在 cellForRowAtIndexPath 中

cell.imageView.image = [UIImage imageNamed:@"checking.png"];
cell.textLabel.text = @"NAME";
cell.detailTextLabel.text = @"Checking...";

如何从另一个函数更新 imageView.image 和 detailTextLabel.text。有 UITableView 方法吗?我猜我需要使用 IndexPath 行来定位单元格。也许为每个 imageView 和 detailTextLabel 分配标签?

谢谢。

4

2 回答 2

0

您更好的选择是更新模型中的数据,然后询问表视图reloadData(或者,如果您特别知道更新了哪些行,则reloadRowsAtIndexPaths:withRowAnimation:)。

这保持了数据模型的完整性,并且是管理视图的最简单的代码。

于 2013-05-14T15:56:27.347 回答
0

您应该尝试使用这样的属性:

@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) NSString *textLabel;
@property (nonatomic, strong) NSString *detailTextLabel;

然后像以前一样将此属性添加到您的单元格中:

cell.imageView.image = image;
cell.textLabel.text = textLabel;
cell.detailTextLabel.text = detailTextLabel;

每当您更新数据时,您都会调用重新加载单元格的方法(使用包含要重新加载的单元格的 indexPath 的数组):

[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
于 2013-05-14T16:10:26.297 回答