我正在使用 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'
如何将 View 包含在我的 View Controller 中?将不胜感激。
最佳答案
在 JSQMessagesCollectionView 中,没有公共(public)方法可以从您的类中初始化该类。但是有一种私有(private)初始化方法可用,即 - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
。
这就是您得到 nil 的原因。
根据文档,最好使用 JSQMessagesViewController。
希望解决方案有所帮助。
关于ios - 使用 JSQMessagesCollectionView 时,“必须使用非零布局参数初始化 UICollectionView”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35912087/