在ios中使用JSQMessageViewController无法获取聊天气泡

在ios中使用JSQMessageViewController无法获取聊天气泡,ios,objective-c,jsqmessagesviewcontroller,Ios,Objective C,Jsqmessagesviewcontroller,我在JSQMessageViewController中没有收到聊天泡泡,但无法获得要添加的方法以在IOS中的聊天页面中收到聊天泡泡。我只收到文本框和发送按钮。当我键入文本并单击发送时,没有收到泡泡。我是新的。请帮助我 // .h File content // ChatpageViewController.h // ChatApp #import <UIKit/UIKit.h> #import <JSQMessages

我在JSQMessageViewController中没有收到聊天泡泡,但无法获得要添加的方法以在IOS中的聊天页面中收到聊天泡泡。我只收到文本框和发送按钮。当我键入文本并单击发送时,没有收到泡泡。我是新的。请帮助我

 //  .h File content
        //  ChatpageViewController.h
        //  ChatApp


    #import <UIKit/UIKit.h>
    #import <JSQMessagesViewController/JSQMessages.h>
    #import <JSQMessagesViewController.h>
    #import "JSQMessagesCollectionViewFlowLayout.h"
    #import "JSQMessages.h"
    #import "JSQPhotoMediaItem.h"
    #import "JSQLocationMediaItem.h"
    #import "JSQVideoMediaItem.h"
    #import "JSQMessagesMediaViewBubbleImageMasker.h"
    #import "JSQMessagesAvatarImage.h"
    #import "JSQMessagesAvatarImageFactory.h"
    #import "JSQMessagesBubbleImage.h"
    #import "JSQMessagesBubbleImageFactory.h"
    #import "UIImage+JSQMessages.h"



    @interface ChatpageViewController : JSQMessagesViewController<JSQMessagesCollectionViewDataSource,JSQMessagesCollectionViewDelegateFlowLayout,JSQMessagesCollectionViewCellDelegate,JSQMessageData,JSQMessageMediaData,JSQMessageAvatarImageDataSource,JSQMessageBubbleImageDataSource>

    @property(nonatomic,strong)NSDictionary * receivedict;


    @property (strong, nonatomic) IBOutlet UILabel *name;
    @property (strong, nonatomic) IBOutlet UILabel *mobile;
    - (IBAction)cancelbtn:(id)sender;


    @end

你的代码中有很多问题。。您没有实现所有的JSQ方法。。请检查如何集成JSQMessageViewController,而不是气泡,这是您的主要问题检查答案如下:-

您必须使用
JSQMessagesBubbleImage
类来获得像

.h
文件中定义

 @property (strong, nonatomic) JSQMessagesBubbleImage *outgoingBubbleImageData;
 @property (strong, nonatomic) JSQMessagesBubbleImage *incomingBubbleImageData;  
.m
文件中的
viewDidLoad

JSQMessagesBubbleImageFactory *bubbleFactory = [[JSQMessagesBubbleImageFactory alloc] init];

self.outgoingBubbleImageData = [bubbleFactory outgoingMessagesBubbleImageWithColor:[UIColor jsq_messageBubbleBlueColor]];
self.incomingBubbleImageData = [bubbleFactory incomingMessagesBubbleImageWithColor:[UIColor jsq_messageBubbleLightGrayColor]];  
而不是提供JSQMessages CollectionView数据源

 - (id<JSQMessageBubbleImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView messageBubbleImageDataForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JSQMessage *message = [messages objectAtIndex:indexPath.item];

    if ([message.senderId isEqualToString:self.senderId]) {
          return self.outgoingBubbleImageData;
    }

    return self.incomingBubbleImageData;
}
-(id)collectionView:(jsqMessageCollectionView*)collectionView消息BubbleImageDataForItemAtIndexPath:(NSIndexPath*)indexPath
{
JSQMessage*message=[messages objectAtIndex:indexath.item];
if([message.senderId isEqualToString:self.senderId]){
返回self.outingbubbleImageData;
}
返回self.incomingBubbleImageData;
}

在我的编码中添加了以下方法后,我尝试了以下方法,然后我得到了以下其他函数的气泡-(无效)按Send按钮:(UIButton*)按钮等

- (id<JSQMessageBubbleImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView messageBubbleImageDataForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JSQMessage *message = [fularray objectAtIndex:indexPath.item];

    if ([message.senderId isEqualToString:self.senderId]) {
        return self.outgoingBubbleImageData;
    }

    return self.incomingBubbleImageData;
}

- (id<JSQMessageAvatarImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView avatarImageDataForItemAtIndexPath:(NSIndexPath *)indexPath {
    return [JSQMessagesAvatarImageFactory avatarImageWithUserInitials:@"JL" backgroundColor:[UIColor blueColor] textColor:[UIColor whiteColor] font:[UIFont systemFontOfSize:12.0] diameter:30.0];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [fularray count];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (id<JSQMessageData>)collectionView:(JSQMessagesCollectionView *)collectionView messageDataForItemAtIndexPath:(NSIndexPath *)indexPath {
    return fularray[indexPath.row];
}
-(id)collectionView:(jsqMessageCollectionView*)collectionView消息BubbleImageDataForItemAtIndexPath:(NSIndexPath*)indexPath
{
JSQMessage*message=[fularray objectAtIndex:indexath.item];
if([message.senderId isEqualToString:self.senderId]){
返回self.outingbubbleImageData;
}
返回self.incomingBubbleImageData;
}
-(id)collectionView:(JSQMessageCollectionView*)collectionView avatarImageDataForItemAtIndexPath:(NSIndexPath*)indexPath{
返回[JSQMessagesAvatarImageFactory avatarImageWithUserInitials:@“JL”backgroundColor:[UIColor blueColor]textColor:[UIColor WHITECLOR]font:[UIFont systemFontOfSize:12.0]直径:30.0];
}
-(NSInteger)collectionView:(UICollectionView*)collectionView项目编号截面:(NSInteger)截面{
返回[数组计数];
}
-(NSInteger)collectionView中的节数:(UICollectionView*)collectionView{
返回1;
}
-(id)collectionView:(JSQMessageCollectionView*)collectionView messageDataForItemAtIndexPath:(NSIndexPath*)indexPath{
返回fularray[indexPath.row];
}

1。您必须将消息添加到数据源中,以便更新底层collectionview并查看实际的气泡(代码中当前注释掉的内容…)2。请张贴真实代码<代码>返回2016年3月18日不是一个
NSDate
…很抱歉,我将该日期放在了返回日期上,但我想知道实现气泡的方法是什么。因为当我点击“发送”时,我会收到一条消息,输入文本字段和发送按钮。没有气泡出现。我在我的.h和.m文件中添加了上述方法。我仍然没有收到气泡,请帮助我,我在下面提到了我的项目文件链接。。您需要向JSQ collectionview提供源代码。。。只需查看演示
- (id<JSQMessageBubbleImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView messageBubbleImageDataForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JSQMessage *message = [fularray objectAtIndex:indexPath.item];

    if ([message.senderId isEqualToString:self.senderId]) {
        return self.outgoingBubbleImageData;
    }

    return self.incomingBubbleImageData;
}

- (id<JSQMessageAvatarImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView avatarImageDataForItemAtIndexPath:(NSIndexPath *)indexPath {
    return [JSQMessagesAvatarImageFactory avatarImageWithUserInitials:@"JL" backgroundColor:[UIColor blueColor] textColor:[UIColor whiteColor] font:[UIFont systemFontOfSize:12.0] diameter:30.0];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [fularray count];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (id<JSQMessageData>)collectionView:(JSQMessagesCollectionView *)collectionView messageDataForItemAtIndexPath:(NSIndexPath *)indexPath {
    return fularray[indexPath.row];
}