Vários UICollectionView em um controlador
Eu tenho uma visão configurada com dois UICollectionViews. Cada uma dessas visualizações tem uma matriz que a suporta com tamanhos diferentes. collection1 é apoiado por array1, e collection2 é apoiado por array2. O problema é que o número sempre retornado para collection1 de numberOfItemsInSection está sendo aplicado a ambas as visualizações de coleção.
Por exemplo, se array1 for tamanho 4 e array2 for tamanho 5, as duas coleções mostrarão 4 elementos. Se array1 for tamanho 5 e array2 for tamanho 4, quando eu rolar coleção2 todo o caminho ele chama cellForItemAtIndexPath com um itemIndex de 5 para collection2 e eu recebo um NSRangeException.
Como posso fazer com que cada coleção use seu próprio tamanho?
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
if(view == self.colleciton1){
return self.array1.count;
} else if (view == self.collection2){
return self.array2.count;
}
return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
if(cv == self.collection1){
CharacterCell *cell = [cv dequeueReusableCellWithReuseIdentifier:FIRST_CELL_IDENTIFIER forIndexPath:indexPath];
cell.label.text = self.array1[indexPath.item];
return cell;
} else if (cv == self.collection2){
EpisodeCell *cell = [cv dequeueReusableCellWithReuseIdentifier:SECOND_CELL_IDENTIFIER forIndexPath:indexPath];
cell.label.text = self.array2[indexPath.item];
return cell;
}
return nil;
}
Eu incluí um repositório git com um projeto ilustrando o problema.
[email protected]: civatrix / MultipleCollectionViews.git