3

ここに画像の説明を入力

このメソッドでは、iOS 用の JSQMessage podfile を使用します。

collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { .. }

またはを使用するように設定するにはどうすればよいですJSQMessagesCollectionViewCellIncomingJSQMessagesCollectionViewCellOutgoing? 他のアプリがこれを行う方法の例を見つけるのは難しいと思います

私のコード;

- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{


    JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell*)[super collectionView:collectionView cellForItemAtIndexPath:indexPath];



    [cell.textView setDataDetectorTypes:UIDataDetectorTypeNone];
    cell.textView.text = nil;

    VICChatMessage <JSQMessageData> *messageData = (VICChatMessage*)[collectionView.dataSource collectionView:collectionView messageDataForItemAtIndexPath:indexPath];
    cell.textView.attributedText = messageData.attributedText;

    return cell;
}
4

3 に答える 3

4

問題を解決できました。それは送信者の詳細に関係していました。

デフォルトではJSQDefaultSender、私のコードは送信者を知っている場合にのみ設定していました。そのため、送信者がわからない場合のフォールバックを使用しました。

アイデアは、

BOOL isOutgoingMessage = [messageSender isEqualToString:self.sender];

ポッドファイル内:JSQMessagesViewController.m

左右どちらかに配置するようにします。

最後に、メッセージを表示する準備ができているコードでこれを行う必要がありました

 if (message.sender.remoteID)
    {
        senderID = @"JSQDefaultSender";
    }
    else
    {
        senderID = @"sender";
    }

これは機能し、私の問題を解決しました。

どうもありがとう

于 2015-07-16T11:14:34.933 に答える
0

メソッドではmessageBubbleImageDataForItemAtIndexPath、メッセージの送信者とユーザーを比較する必要があります。送信者がユーザーの場合は、outgoingMessagesBubbleImage. そうでない場合は、incomingMessagesBubbleImage

- (id<JSQMessageBubbleImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView messageBubbleImageDataForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JSQMessagesBubbleImageFactory *bubbleFactory = [[JSQMessagesBubbleImageFactory alloc] init];
    Message *message = [your_messages objectAtIndex:indexPath.item];

    if ([message.senderId isEqualToString:self.senderId]) {
        return [bubbleFactory outgoingMessagesBubbleImageWithColor:[UIColor jsq_messageBubbleBlueColor]];
    }

    return [bubbleFactory incomingMessagesBubbleImageWithColor:[UIColor jsq_messageBubbleLightGrayColor]];
}
于 2015-07-15T14:21:27.440 に答える