두 개의 UICollectionView로 뷰를 설정했습니다. 각보기에는 크기가 다른 배열이 배열되어 있습니다. collection1은 array1에 의해 지원되고 collection2는 array2에 의해 지원됩니다. 문제는 numberOfItemsInSection에서 collection1에 대해 반환 된 숫자가 두 컬렉션 뷰에 모두 적용된다는 것입니다.하나의 컨트롤러에있는 여러 개의 UICollectionView
예를 들어, array1의 크기가 4이고 array2의 크기가 5이면 두 컬렉션 모두 4 개의 요소가 표시됩니다. array1의 크기가 5이고 array2의 크기가 4 인 경우 collection2를 스크롤하면 collectionFor2에 대해 itemIndex가 5 인 cellForItemAtIndexPath가 호출되고 NSRangeException이 발생합니다.
각 컬렉션보기에 자체 크기를 사용하려면 어떻게해야합니까?
- (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 repo가 포함되었습니다.
[email protected] : civatrix/MultipleCollectionViews.git
이것은 맞습니다. 나는 똑같은 문제가 있었다. 덕분에 –
! 이게 내 문제를 해결했습니다! – ordinaryman09
Up and Thanks !! 너무 내 꺼야! – z33