修改了公屏的保存最大的数量

This commit is contained in:
fengshuo
2021-11-01 14:14:49 +08:00
committed by zu
parent b58ace2237
commit 80f7624847
2 changed files with 10 additions and 0 deletions

View File

@@ -18,6 +18,8 @@ static CGFloat kRoomMessageDefalutFont = 12;
static CGFloat kRoomMessageTextSpaceHeight = 10; static CGFloat kRoomMessageTextSpaceHeight = 10;
static CGFloat kRoomMessageBubbleCornerRadius = 7; static CGFloat kRoomMessageBubbleCornerRadius = 7;
///公屏保存的最大数
static CGFloat kRoomMessageMaxLength = 1000;
#endif /* XPRoomMessageConstant_h */ #endif /* XPRoomMessageConstant_h */

View File

@@ -124,12 +124,20 @@
if (self.tempArray.count < 1) { if (self.tempArray.count < 1) {
return; return;
} }
if (self.datasource.count > kRoomMessageMaxLength) {
NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)];
NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set];
[self.datasource removeObjectsInArray:needRemoveMsgArray];
}
// //
NSMutableArray *indexPaths = [NSMutableArray array]; NSMutableArray *indexPaths = [NSMutableArray array];
for (XPRoomMessageDisplayModel *item in self.tempArray) { for (XPRoomMessageDisplayModel *item in self.tempArray) {
[self.datasource addObject:item]; [self.datasource addObject:item];
[indexPaths addObject:[NSIndexPath indexPathForRow:self.datasource.count - 1 inSection:0]]; [indexPaths addObject:[NSIndexPath indexPathForRow:self.datasource.count - 1 inSection:0]];
} }
NSLog(@"消息的总数%ld", self.datasource.count);
[self.messageTableView reloadData]; [self.messageTableView reloadData];
[self.tempArray removeAllObjects]; [self.tempArray removeAllObjects];