添加二级评论多个的时候的逻辑,默认每次点击出现5条
This commit is contained in:
@@ -67,6 +67,14 @@
|
||||
forState:UIControlStateNormal];
|
||||
break;
|
||||
}
|
||||
case KBAIReplyFooterStateLoadMore: {
|
||||
self.actionButton.hidden = NO;
|
||||
NSInteger remaining = comment.totalReplyCount - comment.displayedReplies.count;
|
||||
title = [NSString stringWithFormat:@"展开更多回复(%ld条)", (long)remaining];
|
||||
[self.actionButton setImage:[UIImage systemImageNamed:@"chevron.down"]
|
||||
forState:UIControlStateNormal];
|
||||
break;
|
||||
}
|
||||
case KBAIReplyFooterStateCollapse: {
|
||||
self.actionButton.hidden = NO;
|
||||
title = @"收起";
|
||||
|
||||
@@ -319,13 +319,17 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
|
||||
|
||||
#pragma mark - Footer Actions
|
||||
|
||||
/// 每次加载的回复数量
|
||||
static NSInteger const kRepliesLoadCount = 5;
|
||||
|
||||
- (void)handleFooterActionForSection:(NSInteger)section {
|
||||
KBAICommentModel *comment = self.comments[section];
|
||||
KBAIReplyFooterState state = [comment footerState];
|
||||
|
||||
switch (state) {
|
||||
case KBAIReplyFooterStateExpand: {
|
||||
[self expandRepliesForSection:section];
|
||||
case KBAIReplyFooterStateExpand:
|
||||
case KBAIReplyFooterStateLoadMore: {
|
||||
[self loadMoreRepliesForSection:section];
|
||||
break;
|
||||
}
|
||||
case KBAIReplyFooterStateCollapse: {
|
||||
@@ -337,15 +341,17 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)expandRepliesForSection:(NSInteger)section {
|
||||
- (void)loadMoreRepliesForSection:(NSInteger)section {
|
||||
KBAICommentModel *comment = self.comments[section];
|
||||
NSInteger currentCount = comment.displayedReplies.count;
|
||||
|
||||
// 一次性展开全部回复
|
||||
[comment expandAllReplies];
|
||||
// 加载更多回复
|
||||
[comment loadMoreReplies:kRepliesLoadCount];
|
||||
|
||||
// 计算要插入的行
|
||||
// 计算新增的行
|
||||
NSInteger newCount = comment.displayedReplies.count;
|
||||
NSMutableArray *insertIndexPaths = [NSMutableArray array];
|
||||
for (NSInteger i = 0; i < comment.displayedReplies.count; i++) {
|
||||
for (NSInteger i = currentCount; i < newCount; i++) {
|
||||
[insertIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:section]];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user