处理发送评论
This commit is contained in:
@@ -475,12 +475,50 @@ static NSInteger const kRepliesLoadCount = 5;
|
|||||||
|
|
||||||
__weak typeof(self) weakSelf = self;
|
__weak typeof(self) weakSelf = self;
|
||||||
_inputView.onSend = ^(NSString *text) {
|
_inputView.onSend = ^(NSString *text) {
|
||||||
// TODO: 发送评论
|
[weakSelf sendCommentWithText:text];
|
||||||
NSLog(@"[KBAICommentView] Send comment: %@", text);
|
|
||||||
[weakSelf.inputView clearText];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return _inputView;
|
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
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user