2

I am working with UICollectionViewController. When I navigate from a UIViewController to a UICollectionViewController by using UINavigationController an exception occurred with message:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter.

I don't know why this happened.

I am using a simple UICollectionViewController without any coding (i.e. by default created file). Its file name is 'NewCollectionViewController.m' & 'NewCollectionViewController.h'.

My Xcode version is 6.1.1.

My navigation code is:

NewCollectionViewController *CVController = [[NewCollectionViewController alloc] init];
[self.navigationController pushViewController:CVController animated:YES];

I just want to navigate from UIViewController to UICollectionViewController.

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
Madan gupta
  • 668
  • 6
  • 19

4 Answers4

1

I guess it's the first time you play with UICollectionViewController.

Just as the exception reason said UICollectionView must be initialized with a non-nil layout parameter. The proper init method of UICollectionViewController is

 - (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout
dopcn
  • 4,218
  • 3
  • 23
  • 32
1

Check The root View having NavigationController and make sure storyBoard Identifier set.

NewCollectionViewController *CVController = (NewCollectionViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"StoryBordIdentifier"]
[self.navigationController pushViewController:CVController animated:YES];

Push to new ViewController

Community
  • 1
  • 1
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
0

you have to add [self.collectionView registerClass:[UICollectionView class] forCellWithReuseIdentifier:@"MyCell"];

in NewCollectionViewController class

Mahesh
  • 956
  • 10
  • 17
0

Create UICollectionViewCell class and UICollectionViewFlowLayout class and add them to your UICollectionViewController class.

Madan gupta
  • 668
  • 6
  • 19
vicky
  • 13
  • 5