Is there any situation where using UICollectionViewController is appropriate compared to using UIViewController + UICollectionView?

Viewed 50

I am quite comfortable in using UICollectionView inside a UIViewController.

I have never used UICollectionViewController before.

I was wondering, is there any situation, where using UICollectionViewController is more appropriate?

2 Answers

UICollectionView inherits from UIScrollView (just another UIView)

UICollectionViewController inherits from UIViewController. and it implements some protocols. like UICollectionViewDelegate and UICollectionViewDataSource. it means everything is already done for you. and you just have to use it.. but as everything is already done for you. you may not be able to do some stuff. like resizing your collectionView.

if you want full control I recommend you to use your own UIViewController.. and add a UICollectionView as a subview.. so you can place it wherever you want and resize it.. don't forget to implement UICollectionView protocols for delegation and datasource.

You may change some properties with your View controllers. But when you use as part of its' controllers, you can't change it.

For example you Cant change UICollectionView Size of UICollectionViewController .

In addition to the obvious -

  1. setting your UICollectionView up for you
  2. automatically marking conformation for necessary protocols like UICollectionViewDataSource & UICollectionViewDelegate

A UICollectionViewController gives you a few built in nice features that you otherwise have to do a lot of extra work to get right manually.

  1. installsStandardGestureForInteractiveMovement

The default value of this property is true. When true, the collection view controller installs a standard gesture recognizer (based on a long-press gesture) to manage the reordering of views inside the collection view. The collection view’s data source must declare its support for reordering items by implementing the appropriate methods. Setting this property to false prevents the installation of this gesture recognizer.

  1. useLayoutToLayoutNavigationTransitions

This property helps facilitate transitions between two or more collection view controllers using a navigation controller. When configuring your navigation controller, install a collection view controller as the root object on the navigation stack and set its value for this property to false. When the user selects an item that would require pushing a new collection view controller on the stack, set the value of this property for the new view controller to true. When you do that, the navigation controller performs an animated layout change between the contents of the two collection view controllers instead of the traditional push animation. Similarly, popping the topmost collection view controller off the stack animates back to the previous layout. The navigation controller drives the transition between the view controllers, including the ability to drive the transition interactively.

You must set the value of this property before pushing the collection view controller onto a navigation stack. Do not change the value of this property after the view controller is already on the navigation stack.


It's up to you if your case is a good candidate for using these features or not and based on that you can make the call.

Related