From 663cb8493bf176273df7f83000c6cc7114d5bc25 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Fri, 16 Jan 2026 19:36:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=8F=91=E9=80=81=E8=AF=84?= =?UTF-8?q?=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyBoard/Class/AiTalk/V/KBAICommentView.m | 44 +++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/keyBoard/Class/AiTalk/V/KBAICommentView.m b/keyBoard/Class/AiTalk/V/KBAICommentView.m index 827b7b9..89f90de 100644 --- a/keyBoard/Class/AiTalk/V/KBAICommentView.m +++ b/keyBoard/Class/AiTalk/V/KBAICommentView.m @@ -475,12 +475,50 @@ static NSInteger const kRepliesLoadCount = 5; __weak typeof(self) weakSelf = self; _inputView.onSend = ^(NSString *text) { - // TODO: 发送评论 - NSLog(@"[KBAICommentView] Send comment: %@", text); - [weakSelf.inputView clearText]; + [weakSelf sendCommentWithText:text]; }; } return _inputView; } +#pragma mark - Send Comment + +- (void)sendCommentWithText:(NSString *)text { + if (text.length == 0) return; + + // 创建新评论 + KBAICommentModel *newComment = [[KBAICommentModel alloc] init]; + newComment.commentId = [NSUUID UUID].UUIDString; + newComment.userId = @"current_user"; + newComment.userName = @"我"; + newComment.avatarUrl = @""; + newComment.content = text; + newComment.likeCount = 0; + newComment.isLiked = NO; + newComment.createTime = [[NSDate date] timeIntervalSince1970]; + newComment.replies = @[]; + + // 计算高度缓存 + CGFloat tableWidth = self.tableView.bounds.size.width; + if (tableWidth <= 0) { + tableWidth = [UIScreen mainScreen].bounds.size.width; + } + newComment.cachedHeaderHeight = [newComment calculateHeaderHeightWithMaxWidth:tableWidth]; + + // 插入到数组第一个 + [self.comments insertObject:newComment atIndex:0]; + self.totalCommentCount++; + [self updateTitle]; + + // 插入新 section + [self.tableView insertSections:[NSIndexSet indexSetWithIndex:0] + withRowAnimation:UITableViewRowAnimationAutomatic]; + + // 滚动到顶部 + [self.tableView setContentOffset:CGPointZero animated:YES]; + + // 清空输入框 + [self.inputView clearText]; +} + @end