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?
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
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];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.