From dd59094a16d3350f7fa90947393df1d60f618960 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Wed, 4 Feb 2026 19:31:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BA=86=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=84=E8=AE=BA=EF=BC=8C=E5=9C=A8=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E9=87=8C=E7=9A=84=E8=AF=84=E8=AE=BA=E6=95=B0=E4=B9=9F?= =?UTF-8?q?=E4=B8=80=E5=90=8C=E6=94=B9=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m | 15 ++++++++++++++- .../Class/AiTalk/V/Comment/KBAICommentInputView.m | 2 ++ keyBoard/Class/AiTalk/V/Comment/KBAICommentView.h | 10 ++++++++++ keyBoard/Class/AiTalk/V/Comment/KBAICommentView.m | 6 ++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m index 2c47029..a6cbce1 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m +++ b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m @@ -22,7 +22,7 @@ /// 聊天会话被重置的通知 static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidResetNotification"; -@interface KBPersonaChatCell () +@interface KBPersonaChatCell () /// 背景图 @property (nonatomic, strong) UIImageView *backgroundImageView; @@ -1250,6 +1250,7 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe CGFloat customViewHeight = KB_SCREEN_HEIGHT * 0.75; KBAICommentView *customView = [[KBAICommentView alloc] initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, customViewHeight)]; + customView.delegate = self; NSString *commentCount = self.persona.commentCount; NSInteger totalCommentCount = [commentCount integerValue];; @@ -1281,6 +1282,18 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe [popView pop]; } +#pragma mark - KBAICommentViewDelegate + +- (void)commentView:(KBAICommentView *)view didUpdateTotalCommentCount:(NSInteger)totalCommentCount { + // 容错:确保回调的人设与当前 cell 的人设一致 + if (view.companionId <= 0 || view.companionId != self.persona.personaId) { + return; + } + + self.persona.commentCount = [NSString stringWithFormat:@"%ld", (long)totalCommentCount]; + [self.commentButton setTitle:self.persona.commentCount forState:UIControlStateNormal]; +} + - (AiVM *)aiVM{ diff --git a/keyBoard/Class/AiTalk/V/Comment/KBAICommentInputView.m b/keyBoard/Class/AiTalk/V/Comment/KBAICommentInputView.m index 7898aad..bef6e48 100644 --- a/keyBoard/Class/AiTalk/V/Comment/KBAICommentInputView.m +++ b/keyBoard/Class/AiTalk/V/Comment/KBAICommentInputView.m @@ -105,6 +105,8 @@ } // 点击发送后清空输入 [self clearText]; + // 发送后收起键盘 + [self.textField resignFirstResponder]; } } diff --git a/keyBoard/Class/AiTalk/V/Comment/KBAICommentView.h b/keyBoard/Class/AiTalk/V/Comment/KBAICommentView.h index 73d9f2a..377e0b8 100644 --- a/keyBoard/Class/AiTalk/V/Comment/KBAICommentView.h +++ b/keyBoard/Class/AiTalk/V/Comment/KBAICommentView.h @@ -10,9 +10,19 @@ NS_ASSUME_NONNULL_BEGIN +@class KBAICommentView; + +@protocol KBAICommentViewDelegate +@optional +/// 评论总数变化回调(例如发送评论/回复成功后) +- (void)commentView:(KBAICommentView *)view didUpdateTotalCommentCount:(NSInteger)totalCommentCount; +@end + /// 抖音风格评论视图 @interface KBAICommentView : UIView +@property(nonatomic, weak, nullable) id delegate; + /// AI 陪聊角色 ID @property(nonatomic, assign) NSInteger companionId; diff --git a/keyBoard/Class/AiTalk/V/Comment/KBAICommentView.m b/keyBoard/Class/AiTalk/V/Comment/KBAICommentView.m index 040f052..7c0ca77 100644 --- a/keyBoard/Class/AiTalk/V/Comment/KBAICommentView.m +++ b/keyBoard/Class/AiTalk/V/Comment/KBAICommentView.m @@ -940,6 +940,9 @@ static NSInteger const kRepliesLoadCount = 5; strongSelf.totalCommentCount += 1; [strongSelf updateTitle]; [strongSelf hideEmptyState]; + if ([strongSelf.delegate respondsToSelector:@selector(commentView:didUpdateTotalCommentCount:)]) { + [strongSelf.delegate commentView:strongSelf didUpdateTotalCommentCount:strongSelf.totalCommentCount]; + } [strongSelf.tableView beginUpdates]; [strongSelf.tableView @@ -1044,6 +1047,9 @@ static NSInteger const kRepliesLoadCount = 5; strongSelf.totalCommentCount += 1; [strongSelf updateTitle]; + if ([strongSelf.delegate respondsToSelector:@selector(commentView:didUpdateTotalCommentCount:)]) { + [strongSelf.delegate commentView:strongSelf didUpdateTotalCommentCount:strongSelf.totalCommentCount]; + } // 若当前已完整展开,则直接插入新行;否则保持 displayedReplies 为前缀,避免破坏 loadMoreReplies 逻辑 if (wasFullyExpanded) {