修改BUG

This commit is contained in:
2026-01-16 20:44:10 +08:00
parent 93489b09d9
commit 552387293c
4 changed files with 77 additions and 50 deletions

View File

@@ -69,8 +69,10 @@
} }
case KBAIReplyFooterStateLoadMore: { case KBAIReplyFooterStateLoadMore: {
self.actionButton.hidden = NO; self.actionButton.hidden = NO;
NSInteger remaining = comment.totalReplyCount - comment.displayedReplies.count; NSInteger remaining =
title = [NSString stringWithFormat:@"展开更多回复(%ld条", (long)remaining]; comment.totalReplyCount - comment.displayedReplies.count;
title =
[NSString stringWithFormat:@"展开更多回复(%ld条", (long)remaining];
[self.actionButton setImage:[UIImage systemImageNamed:@"chevron.down"] [self.actionButton setImage:[UIImage systemImageNamed:@"chevron.down"]
forState:UIControlStateNormal]; forState:UIControlStateNormal];
break; break;
@@ -108,8 +110,8 @@
// //
_actionButton.semanticContentAttribute = _actionButton.semanticContentAttribute =
UISemanticContentAttributeForceLeftToRight; UISemanticContentAttributeForceLeftToRight;
_actionButton.imageEdgeInsets = UIEdgeInsetsMake(0, 4, 0, -4); _actionButton.imageEdgeInsets = UIEdgeInsetsMake(0, -2, 0, 2);
_actionButton.titleEdgeInsets = UIEdgeInsetsMake(0, -4, 0, 4); _actionButton.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, -2);
[_actionButton addTarget:self [_actionButton addTarget:self
action:@selector(actionButtonTapped) action:@selector(actionButtonTapped)

View File

@@ -21,6 +21,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 清空输入框 /// 清空输入框
- (void)clearText; - (void)clearText;
/// 弹起键盘
- (void)showKeyboard;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@@ -83,6 +83,10 @@
[self updateSendButtonState]; [self updateSendButtonState];
} }
- (void)showKeyboard {
[self.textField becomeFirstResponder];
}
#pragma mark - Actions #pragma mark - Actions
- (void)sendButtonTapped { - (void)sendButtonTapped {

View File

@@ -93,7 +93,8 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
[self.inputView mas_makeConstraints:^(MASConstraintMaker *make) { [self.inputView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self); make.left.right.equalTo(self);
make.height.mas_equalTo(50); make.height.mas_equalTo(50);
self.inputBottomConstraint = make.bottom.equalTo(self).offset(-KB_SafeAreaBottom()); self.inputBottomConstraint =
make.bottom.equalTo(self).offset(-KB_SafeAreaBottom());
}]; }];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -148,7 +149,8 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
[self.inputBottomConstraint uninstall]; [self.inputBottomConstraint uninstall];
[self.inputView mas_updateConstraints:^(MASConstraintMaker *make) { [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
self.inputBottomConstraint = make.bottom.equalTo(self); self.inputBottomConstraint =
make.bottom.equalTo(self).offset(-KB_SafeAreaBottom());
}]; }];
[UIView animateWithDuration:duration [UIView animateWithDuration:duration
@@ -196,10 +198,12 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
for (NSDictionary *dict in commentsArray) { for (NSDictionary *dict in commentsArray) {
KBAICommentModel *comment = [KBAICommentModel mj_objectWithKeyValues:dict]; KBAICommentModel *comment = [KBAICommentModel mj_objectWithKeyValues:dict];
// Header // Header
comment.cachedHeaderHeight = [comment calculateHeaderHeightWithMaxWidth:tableWidth]; comment.cachedHeaderHeight =
[comment calculateHeaderHeightWithMaxWidth:tableWidth];
// Reply // Reply
for (KBAIReplyModel *reply in comment.replies) { for (KBAIReplyModel *reply in comment.replies) {
reply.cachedCellHeight = [reply calculateCellHeightWithMaxWidth:tableWidth]; reply.cachedCellHeight =
[reply calculateCellHeightWithMaxWidth:tableWidth];
} }
[self.comments addObject:comment]; [self.comments addObject:comment];
} }
@@ -365,7 +369,8 @@ static NSInteger const kRepliesLoadCount = 5;
NSInteger newCount = comment.displayedReplies.count; NSInteger newCount = comment.displayedReplies.count;
NSMutableArray *insertIndexPaths = [NSMutableArray array]; NSMutableArray *insertIndexPaths = [NSMutableArray array];
for (NSInteger i = currentCount; i < newCount; i++) { for (NSInteger i = currentCount; i < newCount; i++) {
[insertIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:section]]; [insertIndexPaths addObject:[NSIndexPath indexPathForRow:i
inSection:section]];
} }
// Header // Header
@@ -391,7 +396,8 @@ static NSInteger const kRepliesLoadCount = 5;
// //
NSMutableArray *deleteIndexPaths = [NSMutableArray array]; NSMutableArray *deleteIndexPaths = [NSMutableArray array];
for (NSInteger i = 0; i < rowCount; i++) { for (NSInteger i = 0; i < rowCount; i++) {
[deleteIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:section]]; [deleteIndexPaths addObject:[NSIndexPath indexPathForRow:i
inSection:section]];
} }
// //
@@ -496,20 +502,26 @@ static NSInteger const kRepliesLoadCount = 5;
#pragma mark - Reply #pragma mark - Reply
- (void)setReplyToComment:(KBAICommentModel *)comment reply:(KBAIReplyModel *)reply { - (void)setReplyToComment:(KBAICommentModel *)comment
reply:(KBAIReplyModel *)reply {
self.replyToComment = comment; self.replyToComment = comment;
self.replyToReply = reply; self.replyToReply = reply;
if (reply) { if (reply) {
// //
self.inputView.placeholder = [NSString stringWithFormat:@"回复 @%@", reply.userName]; self.inputView.placeholder =
[NSString stringWithFormat:@"回复 @%@", reply.userName];
} else if (comment) { } else if (comment) {
// //
self.inputView.placeholder = [NSString stringWithFormat:@"回复 @%@", comment.userName]; self.inputView.placeholder =
[NSString stringWithFormat:@"回复 @%@", comment.userName];
} else { } else {
// //
self.inputView.placeholder = @"说点什么..."; self.inputView.placeholder = @"说点什么...";
} }
//
[self.inputView showKeyboard];
} }
- (void)clearReplyTarget { - (void)clearReplyTarget {
@@ -521,7 +533,8 @@ static NSInteger const kRepliesLoadCount = 5;
#pragma mark - Send Comment #pragma mark - Send Comment
- (void)sendCommentWithText:(NSString *)text { - (void)sendCommentWithText:(NSString *)text {
if (text.length == 0) return; if (text.length == 0)
return;
CGFloat tableWidth = self.tableView.bounds.size.width; CGFloat tableWidth = self.tableView.bounds.size.width;
if (tableWidth <= 0) { if (tableWidth <= 0) {
@@ -555,7 +568,8 @@ static NSInteger const kRepliesLoadCount = 5;
newComment.replies = @[]; newComment.replies = @[];
// //
newComment.cachedHeaderHeight = [newComment calculateHeaderHeightWithMaxWidth:tableWidth]; newComment.cachedHeaderHeight =
[newComment calculateHeaderHeightWithMaxWidth:tableWidth];
// //
[self.comments insertObject:newComment atIndex:0]; [self.comments insertObject:newComment atIndex:0];
@@ -572,7 +586,8 @@ static NSInteger const kRepliesLoadCount = 5;
- (void)sendReplyWithText:(NSString *)text tableWidth:(CGFloat)tableWidth { - (void)sendReplyWithText:(NSString *)text tableWidth:(CGFloat)tableWidth {
KBAICommentModel *comment = self.replyToComment; KBAICommentModel *comment = self.replyToComment;
if (!comment) return; if (!comment)
return;
// //
KBAIReplyModel *newReply = [[KBAIReplyModel alloc] init]; KBAIReplyModel *newReply = [[KBAIReplyModel alloc] init];
@@ -591,7 +606,8 @@ static NSInteger const kRepliesLoadCount = 5;
} }
// //
newReply.cachedCellHeight = [newReply calculateCellHeightWithMaxWidth:tableWidth]; newReply.cachedCellHeight =
[newReply calculateCellHeightWithMaxWidth:tableWidth];
// replies // replies
NSMutableArray *newReplies = [NSMutableArray arrayWithArray:comment.replies]; NSMutableArray *newReplies = [NSMutableArray arrayWithArray:comment.replies];
@@ -601,14 +617,16 @@ static NSInteger const kRepliesLoadCount = 5;
// section // section
NSInteger section = [self.comments indexOfObject:comment]; NSInteger section = [self.comments indexOfObject:comment];
if (section == NSNotFound) return; if (section == NSNotFound)
return;
// displayedReplies // displayedReplies
if (comment.isRepliesExpanded) { if (comment.isRepliesExpanded) {
NSInteger newRowIndex = comment.displayedReplies.count; NSInteger newRowIndex = comment.displayedReplies.count;
[comment.displayedReplies addObject:newReply]; [comment.displayedReplies addObject:newReply];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowIndex inSection:section]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowIndex
inSection:section];
[self.tableView insertRowsAtIndexPaths:@[ indexPath ] [self.tableView insertRowsAtIndexPaths:@[ indexPath ]
withRowAnimation:UITableViewRowAnimationAutomatic]; withRowAnimation:UITableViewRowAnimationAutomatic];