Reputation: 668
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
.
Upvotes: 2
Views: 174
Reputation: 13
Create UICollectionViewCell
class and UICollectionViewFlowLayout
class and add them to your UICollectionViewController
class.
Upvotes: 0
Reputation: 7973
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];
Upvotes: 1
Reputation: 996
you have to add
[self.collectionView registerClass:[UICollectionView class] forCellWithReuseIdentifier:@"MyCell"];
in NewCollectionViewController class
Upvotes: 0
Reputation: 4218
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
Upvotes: 1