私が見つけた最良のアプローチは、 and をサブクラスJSQMessagesCollectionViewCellIncoming
化することでしたJSQMessagesCollectionViewCellOutgoing
。これは非常に重要です。ライブラリはこれらの型のいずれかを想定しているため、JSQMessagesCollectionViewCell
直接サブクラス化すると問題が発生します。ところで、既存の をコピーし、JSQMessagesCollectionViewCellOutgoing.xib
すべてJSQMessagesCollectionViewCellIncoming.xib
を変更/名前変更したため、セルのカスタマイズを簡単に開始できました。
次に、JSQMessagesViewController サブクラスで、次のように viewDidLoad() にセル識別子を登録します。
self.outgoingCellIdentifier = [CustomCollectionViewCellOutgoing cellReuseIdentifier];
self.outgoingMediaCellIdentifier = [CustomCollectionViewCellOutgoing mediaCellReuseIdentifier];
[self.collectionView registerNib:[CustomCollectionViewCellOutgoing nib] forCellWithReuseIdentifier:self.outgoingCellIdentifier];
[self.collectionView registerNib:[CustomCollectionViewCellOutgoing nib] forCellWithReuseIdentifier:self.outgoingMediaCellIdentifier];
self.incomingCellIdentifier = [CustomCollectionViewCellIncoming cellReuseIdentifier];
self.incomingMediaCellIdentifier = [CustomCollectionViewCellIncoming mediaCellReuseIdentifier];
[self.collectionView registerNib:[CustomCollectionViewCellIncoming nib] forCellWithReuseIdentifier:self.incomingCellIdentifier];
次に、collectionView:cellForItemAtIndexPath: でカスタム セルにアクセスできます。
[self.collectionView registerNib:[CustomCollectionViewCellIncoming nib] forCellWithReuseIdentifier:self.incomingMediaCellIdentifier];
回答元リンク: https://github.com/jessesquires/JSQMessagesViewController/issues/1233