2

Same code for iOS6 worked fine.

For some reason when updating to iOS7 and using this layout

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];

    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
 /
    CGSize s = CGSizeMake(self.collectionView.frame.size.height,self.collectionView.frame.size.height);

    [flowLayout setItemSize:s];

the collectionview delegate methods aren't called. I changed the scroll direction to vertical, all delegates are called, I changed the frame size of the collectionview to be larger and the delegate methods are called. I suspect that the collectionview is for somereason offset inside its content view, causing the cells to be offscreen, inturn the delegates aren't called. When making the frame larger (in horizontal or vertical mode) the collectionview "fills" the scrollview and the delegates are called

normal size collectionview (no cells and delegate aren't called)

enter image description here

enlarged the frame by 50 px

CGRect r = CGRectInset(self.filmStripRect, 0, -50);

cells appear and delegates are called

enter image description here

Avba
  • 14,822
  • 20
  • 92
  • 192
  • Did you set the scroll direction in storyboard too? – Nick Terry Sep 23 '13 at 14:56
  • 1
    Not using story board – Avba Sep 23 '13 at 14:59
  • 1
    Ah. You have your cell .itemSize set to the same as your collectionview size. Maybe that's it? Each cell would be the same size as your entire collectionview. Test by just making CGSize s 20,20. – Nick Terry Sep 23 '13 at 15:07
  • it has something to do with this http://stackoverflow.com/questions/13780138/dynamically-setting-layout-on-uicollectionview-causes-inexplicable-contentoffset/14075292#14075292 – Avba Sep 23 '13 at 15:10

3 Answers3

3

you should also check those to make horizontal scroll work:

Gulz
  • 1,773
  • 19
  • 15
2

we should create a new CollectionViewLayout, and resign it to the collectionView:

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
self.collectionView.collectionViewLayout = flowLayout;
Wayne Chen
  • 305
  • 2
  • 15
  • programmatically changing the scroll direction of the EXISTING flow layout didn't work. Creating a new one was the correct solution for me. Thanks – anders Apr 12 '18 at 18:12
1
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[CollectionData setCollectionViewLayout:flowLayout];

If you are using storyboard,select a collectionview,go to attribute inspector an set the scroll direction horizontal.

Preetha
  • 753
  • 9
  • 12