HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS UITableView reloadRowsAtIndexPaths大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个UITableview,懒惰加载所有不同大小的图像.当图像加载时,我需要更新特定的单元格,所以我想出我需要使用reloadRowsATindexPaths.但是当我使用这种方法时,它仍然为每个单元格调用heightForRowATindexPath方法.我认为reloadRowsATindexPaths的整个目的是它只会为你指定的特定行调用heightForRowATindexPath?

任何想法为什么?

[self.messageTableView beginupdates];
[self.messageTableView reloadRowsATindexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
[self.messageTableView endupdates];

谢谢

解决方法

endupdates触发内容大小重新计算,这需要heightForRowATindexPath.这就是它的工作原理

如果这是一个问题,您可以将单元格配置逻辑拉到cellForRowATindexPath之外,并直接重新配置单元格,而无需通过reloadRowsATindexPaths.这是一个基本的概述:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath
{
    NSString *cellId = ...;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:cellId];
    }
    [self tableView:tableView configureCell:cell aTindexPath:indexPath];
    return cell;
}

- (void)tableView:(UITableView *)tableView configureCell:(UITableViewCell *)cell aTindexPath:(NSIndexPath *)indexPath
{
    //cell configuration logic here
}

然后,无论您当前正在调用reloadRowsATindexPaths,您都可以这样做,而不会调用heightForRowATindexPath:

UITableViewCell *cell = [self.messageTableView cellForRowATindexPath:indexPath];
[self tableView:self.messageTableView configureCell:cell aTindexPath:indexPath];

大佬总结

以上是大佬教程为你收集整理的iOS UITableView reloadRowsAtIndexPaths全部内容,希望文章能够帮你解决iOS UITableView reloadRowsAtIndexPaths所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。