0

I have three different kind of objects that I want to display in collection view. But if in section 0 is only 1 element, next section starts from new column.

enter image description here

Can I tell to the layout that it should show items in different sections one after the other with no breaks?

AlKozin
  • 904
  • 8
  • 25

2 Answers2

0

Sure, but if that never changes, why not make two side-by-side sub views? The left one contains the one element, the right one contains the collection view you originally planned to use.

That way the layout doesn't need to know how to work around the left element.

Additionally, you can use one data source. Make datasource[0] the left one, And use datasource[indexPath.row +1] for the whole cellForRow..... method.

Just remember to set total cells in the collection view to [datasource count] -1

Nick Esposito
  • 395
  • 2
  • 6
  • I think, it's not right solution. It's not so good to create custom abstraction on one section that should represent 3 sections because UICollectionView already have this abstraction. And magic values like + 1 or - 1 is not cute too. Even if I create constants for them. Code like this isn't clean and isn't easy to support. – AlKozin Jul 31 '14 at 05:43
  • Sorry, I misread what you were trying to do. If cells are all the same size, why not subclass UITableViewCell to have 3 subviews, and use a hash with three keys to determine which sections of a cell should be populated? This is the same way you'd approach a sectioned table view, except that the sections are vertical – Nick Esposito Aug 01 '14 at 14:11
  • I think, it's not good idea too. Looks like hacking around. An dividing count of elements to 3 not so pretty. – AlKozin Aug 04 '14 at 06:50
0

My solution is to use 1 section and create methods for determinate abstract sections. In addition, I add -infoItemsCount, -visibleItemsCount and -hiddenItemsCount and same methods for generating cells and other.

AlKozin
  • 904
  • 8
  • 25