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

我有一个UITableView使用UITableViewCells 的自定义。每个UITableViewCell按钮都有2个按钮。单击这些按钮将更改UIImageView单元格中的图像。

是否可以分别刷新每个单元以显示新图像?任何帮助表示赞赏。


侃侃无极
浏览 626回答 3
3回答

杨魅力

有了单元格的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]; 当然,您可以设置任何喜欢的动画效果。

守着星空守着你

我尝试仅致电-[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];}

吃鸡游戏

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){    ....}
打开App,查看更多内容
随时随地看视频慕课网APP