@@ -264,26 +264,33 @@ - (void)removeMessageAtIndexPath:(NSIndexPath *)indexPath {
264264- (void )insertOldMessages : (NSArray *)oldMessages {
265265 WEAKSELF
266266 [self exChangeMessageDataSourceQueue: ^{
267- NSMutableArray *messages = [NSMutableArray arrayWithArray: oldMessages];
268- [messages addObjectsFromArray: weakSelf.messages];
267+ NSMutableArray *messages = [[NSMutableArray alloc ] initWithArray: weakSelf.messages];
269268
270269 delayOffset = weakSelf.messageTableView .contentOffset ;
271- NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity: oldMessages.count];
270+ NSMutableArray *indexPaths = [[NSMutableArray alloc ] initWithCapacity: oldMessages.count];
271+ NSMutableIndexSet *indexSets = [[NSMutableIndexSet alloc ] init ];
272272 [oldMessages enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
273273 NSIndexPath *indexPath = [NSIndexPath indexPathForRow: idx inSection: 0 ];
274274 [indexPaths addObject: indexPath];
275275
276276 delayOffset.y += [weakSelf calculateCellHeightWithMessage: [messages objectAtIndex: idx] atIndexPath: indexPath];
277+ [indexSets addIndex: idx];
277278 }];
279+ [messages insertObjects: oldMessages atIndexes: indexSets];
280+
278281
279282 [weakSelf exMainQueue: ^{
280283 [UIView setAnimationsEnabled: NO ];
284+ [self .messageTableView beginUpdates ];
285+
281286 weakSelf.messages = messages;
282287 [weakSelf.messageTableView insertRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationNone];
283288
284- [weakSelf.messageTableView setContentOffset: delayOffset animated: NO ];
289+ [self .messageTableView endUpdates ];
290+
285291 [UIView setAnimationsEnabled: YES ];
286292
293+ [weakSelf.messageTableView setContentOffset: delayOffset animated: NO ];
287294 }];
288295 }];
289296}
0 commit comments