0

I am trying to use this as a starting point to learn about collection view: Creating a UICollectionView programmatically

I have a viewDidLoad which has a UIScrollView created like so:

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 64.0, 

screenWidth, screenHeight)];

How do I add in the UICollectionViewController as the following below doesn't work:

ACollectionViewControllerr *vc = [[ACollectionViewController alloc] init];

[self.view addSubview:vc];

Do you need a UIScrollView to scroll down or does uicollectionview have that functionality already?

Community
  • 1
  • 1
cdub
  • 21,144
  • 49
  • 157
  • 274

2 Answers2

1

UICollectionView inherits from UIScrollView, so you don't need to add an UIScrollView. Just add the UICollectionView to the UIViewController directly.

If you use UICollectionViewController then you don't require UIViewController.

See the documentation of UICollectionView

tkanzakic
  • 5,469
  • 16
  • 34
  • 41
Yogesh Suthar
  • 29,554
  • 17
  • 66
  • 96
0

You're trying to add a ViewController to a view, which will not work. Try the following instead:

ACollectionViewControllerr *vc = [[ACollectionViewController alloc] init];

[self.view addSubView:vc.view];
[vc didMoveToParentViewController];
dezinezync
  • 2,364
  • 18
  • 14