KARTHIK.SETTY
KARTHIK.SETTY

Reputation: 91

Is it possible to keep a collection view inside another collection view?

I have a scenario where if we click or select any cell inside a collection view which is in vertical scrolling, it should display a single row horizontal scrolling below the selected, this should applied for all the cells, so I have created a collection view inside the view controller, and I thought of creating another collection view inside the method:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{}

Because here not only collection view is creating, but also the next cells are moving down. Hope you understand the situation. But I was struck here. I'm not getting any idea how to write code here,

1) Is my approach is correct, 2) If yes, give me some instructions how to achieve this? 3) If I insert a cell, it will insert a cell but it should be horizontal scroll as shown in the image i posted. so Help me out ??

This Type of Collection View I'm expecting

Upvotes: 1

Views: 881

Answers (1)

Irfan
Irfan

Reputation: 5130

One way to achieve your design would be:

  • Add two type of UIcollectionviewcells to collection view
  • cell1: cell1 is the normal cell on which you click.
  • cell2: You will insert this cell at indexpath + 1 in collectionview when tapped on normal cell

  • Add a scroll view to cell2. with horizontal scrolling or collectionview.

  • cell2 will be the datasource and will contains logic for that view.

This will make a lot easy for handling events.

Upvotes: 2

Related Questions