1

I am using JSQMessagesViewController to add chat functionality to my app. Inside a UIViewController, I initialised a JSQMessagesCollectionView thus:

JSQMessagesCollectionView *jsq = [[JSQMessagesCollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:jsq];

This however, is giving me this error:

'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'

How would I include the view inside my view controller? A brief explanation would be much appreciated.

  • Use the designated initializer. If you don't know what that means, google for it. – Avi Mar 10 '16 at 09:16

1 Answers1

1

In JSQMessagesCollectionView, there is no public method to initialize the class from your class. But there is one private init method available i.e. - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout.

This is the reason you are getting nil.

As per documentation, better to use JSQMessagesViewController.

Hope the solution helps.

RJV Kumar
  • 2,408
  • 1
  • 19
  • 28