Несколько UICollectionView в одном контроллере
У меня есть представление, настроенное с двумя UICollectionViews. Каждое из этих представлений имеет массив с разными размерами. collection1 поддерживается массивом1, а collection2 - массивом2. Проблема в том, что любое возвращаемое число для collection1 из numberOfItemsInSection применяется к обоим представлениям коллекции.
Например, если array1 имеет размер 4, а array2 имеет размер 5, обе коллекции будут отображать 4 элемента. Если array1 имеет размер 5, а array2 имеет размер 4, когда я прокручиваю collection2 полностью, он вызывает cellForItemAtIndexPath с itemIndex, равным 5 для collection2, и я получаю исключение NSRangeException.
Как я могу заставить каждый collectionView использовать свой собственный размер?
- (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;
}
Я включил git-репо в проект, иллюстрирующий проблему.
[email protected]: civatrix / MultipleCollectionViews.git