'UICollectionView must be initialized with a non-nil layout parameter' 在使用 JSQMessagesCollectionView 时
'UICollectionView must be initialized with a non-nil layout parameter' while using JSQMessagesCollectionView
我正在使用 JSQMessagesViewController 向我的应用程序添加聊天功能。在 UIViewController 中,我初始化了一个 JSQMessagesCollectionView:
JSQMessagesCollectionView *jsq = [[JSQMessagesCollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:jsq];
然而,这给了我这个错误:
'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
如何将视图包含在我的视图控制器中?将不胜感激。
在 JSQMessagesCollectionView 中,没有 public 方法从您的 class 初始化 class。但是有一种私有初始化方法可用,即 - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
。
这就是您得到 nil 的原因。
根据文档,最好使用 JSQMessagesViewController。
希望解决方案有所帮助。
我正在使用 JSQMessagesViewController 向我的应用程序添加聊天功能。在 UIViewController 中,我初始化了一个 JSQMessagesCollectionView:
JSQMessagesCollectionView *jsq = [[JSQMessagesCollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:jsq];
然而,这给了我这个错误:
'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
如何将视图包含在我的视图控制器中?将不胜感激。
在 JSQMessagesCollectionView 中,没有 public 方法从您的 class 初始化 class。但是有一种私有初始化方法可用,即 - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
。
这就是您得到 nil 的原因。
根据文档,最好使用 JSQMessagesViewController。
希望解决方案有所帮助。