我在objective-c中的项目使用JSQMessagesViewController进行firebase聊天,但气泡图像没有附带消息。 通过Pod集成的JSQMessagesViewController和Firbase。
请帮帮我。
答案 0 :(得分:1)
创建方法初始化发件人和收件人的颜色,如下面的代码:
- (JSQMessagesBubbleImage *) setupOutgoingBubble {
JSQMessagesBubbleImageFactory *bubbleImageFactory = [[JSQMessagesBubbleImageFactory alloc] init];
JSQMessagesBubbleImage * imgBubble = [bubbleImageFactory outgoingMessagesBubbleImageWithColor:[UIColor blueColor]];//jsq_messageBubbleBlueColor return imgBubble;
return imgBubble;
}
- (JSQMessagesBubbleImage *) setupIncomingBubble {
JSQMessagesBubbleImageFactory *bubbleImageFactory = [[JSQMessagesBubbleImageFactory alloc] init];
JSQMessagesBubbleImage * imgBubble = [bubbleImageFactory outgoingMessagesBubbleImageWithColor:[UIColor greenColor]];//jsq_messageBubbleBlueColor return imgBubble;
return imgBubble;
}
- (void)setupBubbleColors {
self.incomingBubbleImageData = [self setupIncomingBubble];
self.outgoingBubbleImageData = [self setupOutgoingBubble];
}
并在viewDidLoad
中调用以上方法,如下所示
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self setupBubbleColors];
}
id JSQMessageBubbleImageDataSource
委托返回适当的图片,如下所示
- (id<JSQMessageBubbleImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView
messageBubbleImageDataForItemAtIndexPath:(NSIndexPath *)indexPath {
Message *message = [_messages objectAtIndex:indexPath.row];
NSLog(@"%@", message.type);
if(message.isOwnMessageValue) {
return self.outgoingBubbleImageData;
}
else return self.incomingBubbleImageData;
}
输出如下所示
答案 1 :(得分:0)
使用firebase N JSQMessagesViewController下载我的聊天应用程序演示
http://www.mediafire.com/file/a8rb2srsbdv643h/firebasechat.zip/file