在这种方法中,使用iOS的JSQMessage Podfile;
collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {..}
如何设置它使用JSQMessagesCollectionViewCellIncoming
或JSQMessagesCollectionViewCellOutgoing
?我发现很难找到其他应用程序如何执行此操作的示例
我的代码;
- (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;
}
我能够解决问题。这与发送者的详细信息有关。
默认情况下,JSQDefaultSender
但我的代码仅在知道发件人的情况下进行设置;因此我在未知发件人时使用了备用。
这个想法是要
BOOL isOutgoingMessage = [messageSender isEqualToString:self.sender];
在podfile中: JSQMessagesViewController.m
以便将它们定位在左侧或右侧。
最后,我必须在代码中执行此操作,以使我的消息准备好显示
if (message.sender.remoteID)
{
senderID = @"JSQDefaultSender";
}
else
{
senderID = @"sender";
}
这有效并解决了我的问题。
非常感谢大家
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句