Ios 更新UITableView';s imageView/detailTextLabel
我正在使用UITableView显示多行数据:textLabel.text表示名称,imageView表示状态(联机/脱机),detailTextLabel表示其他信息 例如,在cellForRowAtIndexPath中Ios 更新UITableView';s imageView/detailTextLabel,ios,uitableview,uiimageview,Ios,Uitableview,Uiimageview,我正在使用UITableView显示多行数据:textLabel.text表示名称,imageView表示状态(联机/脱机),detailTextLabel表示其他信息 例如,在cellForRowAtIndexPath中 cell.imageView.image = [UIImage imageNamed:@"checking.png"]; cell.textLabel.text = @"NAME"; cell.detailTextLabel.text = @"Checking..."; 如
cell.imageView.image = [UIImage imageNamed:@"checking.png"];
cell.textLabel.text = @"NAME";
cell.detailTextLabel.text = @"Checking...";
如何从其他函数更新imageView.image和detailTextLabel.text。是否有UITableView方法?
我猜我需要使用IndexPath行来定位单元格。也许为每个imageView和detailTextLabel分配标签
谢谢。您更好的选择是更新模型中的数据,然后要求表视图重新加载数据(或者,如果您明确知道哪些行已更新,
reloadrowsatinexpaths:withRowAnimation:
)
这保持了数据模型的完整性,是管理视图的最简单代码。您应该尝试使用如下属性:
@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的数组):
但是如何定位一行(IndexPath.row)并更新detailTextLabel和imageView.image?你能提供一些示例代码吗?谢谢。您正在实现表视图数据源方法,对吗?tableView:CellForRowatineXpath:是的,我最终使用了如下内容:UITableViewCell*cell0=[self.tableView CellForRowatineXpath:[nsIndepath indexPathForRow:0第0节:0]];其中indexPathForRow和inSection是固定的。Frm我能够像这样更新cell0.imageView.image=[UIImage ImageName:@“connected.png”];也不工作:[self.tableView beginUpdates];detailTextLabel1=@“新详细信息文本”;[self.tableView重新加载rowsatindexpaths:[NSArray arrayWithObject:[nsIndepath indexPathForRow:0第1部分:0]]带RowAnimation:UITableViewRowAnimationFade];[self.tableView endUpdates];[self.tableView重载数据];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];