问题
My UICollectionView is set to have 3 rows and 3 sections. I am trying to insert a batch (array) 9 of items into the CollectionView, but with the following code below, I get the first 3 things in my batch displayed in all 3 sections.
BATCH: blue, red, green, orange, fish, sand, hat, shoe, black
CURRENT RESULT SHOWN:
blue blue blue
red red red
green green green
CURRENT CODE:
...
[self.selectedSearches addObject:string];
[self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.selectedSearches.count-1 inSection:0]]];
...
Not sure what I am doing wrong.
回答1:
The issuse is I had
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 3;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 3;
}
Should be
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.arrayOfThings.count;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
来源:https://stackoverflow.com/questions/24961081/trying-to-insert-new-items-into-uicollectionview-but-getting-the-same-cells-over