我的UITableViewCotroller的每个单元格上的详细信息标签给出了它所代表的文件夹的大小。大小可能会改变,无论何时,我都需要更改所有detailLabel。一种方法是执行重新加载,[tableview reloadData];但是许多图像使它变慢。有没有办法只更新标签?
我尝试了这种方法,但我似乎无法让它发挥作用:
[tableView beginUpdates];
…
[tableView endUpdates];
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.detailTextLabel.text = @"";
return cell;
}
答案 0 :(得分:0)
一种解决方案可能是通过[self.tableview visibleCells]
快速枚举,并更改这些标签。这假设tableview在cellForRowAtIndexPath
中获得的数据将是最新的。这样,所有可见的单元格将立即更新,其余的将在它们可见后立即更新。
那可以理解吗?如果不是,请告诉我。
答案 1 :(得分:0)
让我们尝试下面的方法,
- (void)loadDetailsForOnscreenRows
{
if ([self.entries count] > 0)
{
NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];
for (NSIndexPath *indexPath in visiblePaths)
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.detailTextLabel.text = @"Your text";
}
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
[self loadDetailsForOnscreenRows];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self loadDetailsForOnscreenRows];
}
另外,请参阅apple的example以获取更多详细信息,以便懒惰加载表格。