为了账号安全,请及时绑定邮箱和手机立即绑定

是否可以刷新UITableView中的单个UITableViewCell?

是否可以刷新UITableView中的单个UITableViewCell?

侃侃无极 2019-11-06 10:17:06
我有一个UITableView使用UITableViewCells 的自定义。每个UITableViewCell按钮都有2个按钮。单击这些按钮将更改UIImageView单元格中的图像。是否可以分别刷新每个单元以显示新图像?任何帮助表示赞赏。
查看完整描述

3 回答

?
杨魅力

TA贡献1811条经验 获得超5个赞

有了单元格的indexPath后,您可以执行以下操作:


[self.tableView beginUpdates];

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathOfYourCell, nil] withRowAnimation:UITableViewRowAnimationNone];

[self.tableView endUpdates]; 

在Xcode 4.6和更高版本中:


[self.tableView beginUpdates];

[self.tableView reloadRowsAtIndexPaths:@[indexPathOfYourCell] withRowAnimation:UITableViewRowAnimationNone];

[self.tableView endUpdates]; 

当然,您可以设置任何喜欢的动画效果。


查看完整回答
反对 回复 2019-11-06
?
守着星空守着你

TA贡献1799条经验 获得超8个赞

我尝试仅致电-[UITableView cellForRowAtIndexPath:],但是没有用。但是,以下示例对我有用。我alloc和release该NSArray用于紧密内存管理。


- (void)reloadRow0Section0 {

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

    NSArray *indexPaths = [[NSArray alloc] initWithObjects:indexPath, nil];

    [self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];

    [indexPaths release];

}


查看完整回答
反对 回复 2019-11-06
?
吃鸡游戏

TA贡献1829条经验 获得超7个赞

reloadRowsAtIndexPaths:很好,但是仍然会迫使UITableViewDelegate方法触发。


我能想到的最简单的方法是:


UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];

[self configureCell:cell forIndexPath:indexPath];

这是重要的调用你configureCell:的主线程中执行,如在非UI线程它不会工作(同样的故事reloadData/ reloadRowsAtIndexPaths:)。有时添加以下内容可能会有所帮助:


dispatch_async(dispatch_get_main_queue(), ^

{

    [self configureCell:cell forIndexPath:indexPath];

});

还有必要避免在当前可见视图之外进行的工作:


BOOL cellIsVisible = [[self.tableView indexPathsForVisibleRows] indexOfObject:indexPath] != NSNotFound;

if (cellIsVisible)

{

    ....

}


查看完整回答
反对 回复 2019-11-06
  • 3 回答
  • 0 关注
  • 620 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信