1

Normaly, if we want to use UICollectionView, we must use an UICollectionViewController. But now I don't want, so how can I use UICollectionView without an UICollectionViewController?

laxonline
  • 2,657
  • 1
  • 20
  • 37
Brian Nguyen
  • 465
  • 1
  • 5
  • 15
  • Check and get sample code, you'll understand: http://stackoverflow.com/questions/14289592/ios-add-a-collectionview-to-a-another-view-within-the-storyboard-ui-builder/14290127#14290127 – LE SANG Jan 13 '13 at 06:30

1 Answers1

3

Of course you can use a UICollectionView without an UICollectionViewController.

Just create a UICollectionViewLayout of your choice, and then call

- (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout

to create a new instance of UICollectionView. Don't forget to set the delegate and datasource of the UICollectionView to your class, and implement the UICollectionViewDataSource protocol.

Hope that helps.

Boris Prohaska
  • 912
  • 6
  • 16
  • I created a class called "nContent" that implement UICollectionView: @interface NContent : UICollectionView . And I set Ncontent as custom class for my UICollectionView, but it still error with message: "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. NContent's implementation of -layoutSubviews needs to call super – Brian Nguyen Jan 12 '13 at 09:34
  • There seems to be something messed up with your auto layout constraints. This has nothing to do with the `UICollectionView` itself. – Boris Prohaska Jan 12 '13 at 09:56