[英]'UICollectionView must be initialized with a non-nil layout parameter' while using JSQMessagesCollectionView
I am using JSQMessagesViewController to add chat functionality to my app. 我正在使用JSQMessagesViewController向我的应用程序添加聊天功能。 Inside a UIViewController, I initialised a JSQMessagesCollectionView thus: 在UIViewController内部,我初始化了一个JSQMessagesCollectionView,因此:
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. 一个简短的解释将不胜感激。
In JSQMessagesCollectionView , there is no public method to initialize the class from your class. 在JSQMessagesCollectionView中 ,没有公共方法可以从您的类中初始化类。 But there is one private init method available ie - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
. 但是有一个私有的初始化方法可用,即- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
。
This is the reason you are getting nil . 这就是你变得零的原因。
As per documentation, better to use JSQMessagesViewController . 根据文档,最好使用JSQMessagesViewController 。
Hope the solution helps. 希望解决方案有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.