Tengo una vista configurada con dos UICollectionViews. Cada una de estas vistas tiene una matriz que la respalda con diferentes tamaños. collection1 está respaldado por array1, y collection2 está respaldado por array2. El problema es que, cualquiera que sea el número devuelto para collection1 from numberOfItemsInSection se está aplicando a ambas vistas de colección.Multiple UICollectionView en un controlador
Por ejemplo, si array1 es tamaño 4 y array2 es tamaño 5, ambas colecciones mostrarán 4 elementos. Si array1 tiene el tamaño 5 y array2 tiene el tamaño 4, cuando recorro collection2 en todo momento, llama a cellForItemAtIndexPath con un itemIndex de 5 para collection2 y obtengo una NSRangeException.
¿Cómo puedo hacer cada colecciónVer usar su propio tamaño?
- (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;
}
He incluido un git repo con un proyecto que ilustra el problema.
[email protected]: civatrix/MultipleCollectionViews.git
Esto es correcto. Yo tuve el mismo problema. –
gracias! ¡esto resolvió mi problema también! – ordinaryman09
¡Arriba y gracias! ¡Resolvió el mío también! – z33