diff --git a/keyBoard/Class/AiTalk/V/KBAICommentView.m b/keyBoard/Class/AiTalk/V/KBAICommentView.m index c8b25ad..6acdf67 100644 --- a/keyBoard/Class/AiTalk/V/KBAICommentView.m +++ b/keyBoard/Class/AiTalk/V/KBAICommentView.m @@ -343,24 +343,55 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; // 一次性展开全部回复 [comment expandAllReplies]; - // 直接刷新该 section -// [UIView performWithoutAnimation:^{ - [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] - withRowAnimation:UITableViewRowAnimationAutomatic]; -// }]; + // 计算要插入的行 + NSMutableArray *insertIndexPaths = [NSMutableArray array]; + for (NSInteger i = 0; i < comment.displayedReplies.count; i++) { + [insertIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:section]]; + } + + // 插入行(不刷新 Header,避免头像闪烁) + [self.tableView beginUpdates]; + if (insertIndexPaths.count > 0) { + [self.tableView insertRowsAtIndexPaths:insertIndexPaths + withRowAnimation:UITableViewRowAnimationAutomatic]; + } + [self.tableView endUpdates]; + + // 手动刷新 Footer + KBAICommentFooterView *footerView = + (KBAICommentFooterView *)[self.tableView footerViewForSection:section]; + if (footerView) { + [footerView configureWithComment:comment]; + } } - (void)collapseRepliesForSection:(NSInteger)section { KBAICommentModel *comment = self.comments[section]; + NSInteger rowCount = comment.displayedReplies.count; + + // 计算要删除的行 + NSMutableArray *deleteIndexPaths = [NSMutableArray array]; + for (NSInteger i = 0; i < rowCount; i++) { + [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:section]]; + } // 收起全部回复 [comment collapseReplies]; - // 直接刷新该 section -// [UIView performWithoutAnimation:^{ - [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] - withRowAnimation:UITableViewRowAnimationAutomatic]; -// }]; + // 删除行(不刷新 Header,避免头像闪烁) + [self.tableView beginUpdates]; + if (deleteIndexPaths.count > 0) { + [self.tableView deleteRowsAtIndexPaths:deleteIndexPaths + withRowAnimation:UITableViewRowAnimationAutomatic]; + } + [self.tableView endUpdates]; + + // 手动刷新 Footer + KBAICommentFooterView *footerView = + (KBAICommentFooterView *)[self.tableView footerViewForSection:section]; + if (footerView) { + [footerView configureWithComment:comment]; + } } #pragma mark - Actions