我正在调用performBatchUpdates来插入和删除collectionview中的单元格。
但是当我这样做时会发出警告。这是我的代码。
-(void)updateActiveuser:(NSMutableArray *)arrActiveUser{
[self.collectionView performBatchUpdates:^{
NSMutableArray *addIndexPath = [NSMutableArray array];
NSMutableArray *removeIndexPath = [NSMutableArray array];
NSMutableArray *arrOffline = [[NSMutableArray alloc] init];
for (User *offlLineuser in self.arrOnlineUsers) {
User *userExist = [self getActiveUserWithUserId:offlLineuser.userID forArray:arrActiveUser];
if (userExist == nil) {
[removeIndexPath addObject:[NSIndexPath indexPathForRow:[self.arrOnlineUsers indexOfObject:offlLineuser] inSection:0]];
[arrOffline addObject:offlLineuser];
}
}
[self.arrOnlineUsers removeObjectsInArray:arrOffline];
NSInteger count = 0;
for (User *obj in arrActiveUser)
{
User *userExist = [self getActiveUserWithUserId:obj.userID forArray:self.arrOnlineUsers];
if (userExist == nil) {
[addIndexPath addObject:[NSIndexPath indexPathForRow:count inSection:0]];
[self.arrOnlineUsers addObject:obj];
count = count +1;
}
}
[self.collectionView insertItemsAtIndexPaths:addIndexPath];
[self.collectionView deleteItemsAtIndexPaths:removeIndexPath];
} completion:^(BOOL finished) {
[self.collectionView reloadData];
}];
}
我正在主线程中调用上述方法。
快照未呈现的视图将导致快照为空。确保在快照之前或屏幕更新后快照中至少渲染过一次视图。