我想找到一種方法將細胞添加到集合中,並且它一直給我「發送給不可變對象的變異方法」錯誤。我不知道爲什麼。下面發佈的是我正在使用的代碼。將細胞添加到現有的UICollectionView(將變異方法發送到不可變對象)
self.artistArray = [responseObject objectForKey:@"data"];
self.paginationArray = [responseObject objectForKey:@"pagination"];
//NSLog(@"%@", self.paginationArray);
if(self.firstRequest){
[self.collectionView reloadData];
self.firstRequest = FALSE;
}
else{
NSArray *newData = [[NSArray alloc] initWithObjects:@"otherData", nil];
[self.collectionView performBatchUpdates:^{
int resultsSize = [self.artistArray count]; //data is the previous array of data
[self.artistArray addObjectsFromArray:newData];
NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
for (int i = resultsSize; i < resultsSize + newData.count; i++) {
[arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i
inSection:0]];
}
[self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];
} completion:nil];
}
如果你們有任何問題,讓我知道,我會盡我所能來回答你。
請,秀** ** artistArray財產申報串 – Brain89
@ Brain89的delcaration是: 'self.artistArray = [[NSMutableArray裏的alloc]初始化]。'在viewDidLoad – hparmar