From 22f77d56ea2f5990f2f9df2e0a291c6346b723b8 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Wed, 28 Jan 2026 15:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=90=E8=97=8F=E6=97=A0=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyBoard/Class/AiTalk/V/KBAICommentView.m | 53 +++++++++++++++++++++++ keyBoard/Class/AiTalk/V/KBChatTableView.m | 6 +++ 2 files changed, 59 insertions(+) diff --git a/keyBoard/Class/AiTalk/V/KBAICommentView.m b/keyBoard/Class/AiTalk/V/KBAICommentView.m index 8fc8128..4c9058d 100644 --- a/keyBoard/Class/AiTalk/V/KBAICommentView.m +++ b/keyBoard/Class/AiTalk/V/KBAICommentView.m @@ -176,6 +176,7 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; - (void)loadComments { if (self.companionId <= 0) { NSLog(@"[KBAICommentView] companionId 未设置,无法加载评论"); + [self showEmptyState]; return; } @@ -191,6 +192,10 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; if (error) { NSLog(@"[KBAICommentView] 加载评论失败:%@", error.localizedDescription); + // 加载失败也显示空态 + dispatch_async(dispatch_get_main_queue(), ^{ + [strongSelf showEmptyStateWithError]; + }); return; } @@ -204,6 +209,8 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; - (void)updateCommentsWithPageModel:(KBCommentPageModel *)pageModel { if (!pageModel) { NSLog(@"[KBAICommentView] pageModel 为空"); + // 数据为空,显示空态 + [self showEmptyState]; return; } @@ -236,6 +243,49 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; [self updateTitle]; [self.tableView reloadData]; + + // 根据数据是否为空,动态控制空态显示 + if (self.comments.count == 0) { + [self showEmptyState]; + } else { + [self hideEmptyState]; + } +} + +/// 显示空态视图 +- (void)showEmptyState { + self.tableView.useEmptyDataSet = YES; + self.tableView.emptyTitleText = @"暂无评论"; + self.tableView.emptyDescriptionText = @"快来抢沙发吧~"; + self.tableView.emptyImage = nil; // 可选:设置空态图片 + self.tableView.emptyVerticalOffset = -50; // 向上偏移一点 + [self.tableView kb_reloadEmptyDataSet]; +} + +/// 显示错误空态视图 +- (void)showEmptyStateWithError { + self.tableView.useEmptyDataSet = YES; + self.tableView.emptyTitleText = @"加载失败"; + self.tableView.emptyDescriptionText = @"点击重新加载"; + self.tableView.emptyImage = nil; + self.tableView.emptyVerticalOffset = -50; + + // 点击重新加载 + __weak typeof(self) weakSelf = self; + self.tableView.emptyDidTapView = ^{ + __strong typeof(weakSelf) strongSelf = weakSelf; + if (strongSelf) { + [strongSelf loadComments]; + } + }; + + [self.tableView kb_reloadEmptyDataSet]; +} + +/// 隐藏空态视图 +- (void)hideEmptyState { + self.tableView.useEmptyDataSet = NO; + [self.tableView kb_reloadEmptyDataSet]; } - (void)updateTitle { @@ -591,6 +641,9 @@ static NSInteger const kRepliesLoadCount = 5; _tableView.backgroundColor = [UIColor clearColor]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; + + // 关闭空数据占位,避免加载时显示"暂无数据" + _tableView.useEmptyDataSet = NO; // 注册 Header/Cell/Footer [_tableView registerClass:[KBAICommentHeaderView class] diff --git a/keyBoard/Class/AiTalk/V/KBChatTableView.m b/keyBoard/Class/AiTalk/V/KBChatTableView.m index daf157e..ef22a69 100644 --- a/keyBoard/Class/AiTalk/V/KBChatTableView.m +++ b/keyBoard/Class/AiTalk/V/KBChatTableView.m @@ -111,6 +111,12 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟 [strongSelf.tableView.mj_footer endRefreshing]; } }]; + + // 隐藏"已经全部加载完毕"的提示文字 + MJRefreshAutoNormalFooter *footer = (MJRefreshAutoNormalFooter *)self.tableView.mj_footer; + footer.stateLabel.hidden = YES; // 隐藏状态文字 + footer.refreshingBlock = footer.refreshingBlock; // 保持刷新逻辑 + self.tableView.mj_footer.hidden = YES; }