1

我没有在 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

M 文件从这里开始

//
//  ChatpageViewController.m
//  ChatApp
//


#import "ChatpageViewController.h"


@interface ChatpageViewController ()
{

}

@end

@implementation ChatpageViewController
@synthesize receivedict,name,mobile;




-(void)viewWillAppear:(BOOL)animated
{

    self.collectionView.collectionViewLayout.springinessEnabled = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
       // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:YES animated:YES];
NSLog(@"%@",receivedict);
    name.text = [receivedict objectForKey:@"Name"];
    id.text =[receivedict objectForKey:@"Id"];



}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSString *)senderId
{
    return [receivedict objectForKey:@"Id"];
}


- (NSString *)senderDisplayName
{

    return [receivedict objectForKey:@"Name"];
}

- (NSDate *)date
{
    return 18/03/2016;
}


- (void)didPressSendButton:(UIButton *)button withMessageText:(NSString *)text senderId:(NSString *)senderId senderDisplayName:(NSString *)senderDisplayName date:(NSDate *)date
{

    [JSQSystemSoundPlayer jsq_playMessageSentSound];

    JSQMessage *message = [[JSQMessage alloc] initWithSenderId:senderId
                                             senderDisplayName:senderDisplayName
                                                          date:date
                                                          text:text];
   // [demoData.messages addObject:message];
    [self finishSendingMessageAnimated:YES];


    NSLog(@"%@",message);
}



- (IBAction)cancelbtn:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
4

2 回答 2

2

您的代码中有很多问题..您没有实现所有 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;
}
于 2016-03-18T10:23:48.273 回答
0

我在我的编码中添加了波纹管方法后尝试了,然后我得到了带有波纹管后其他功能的气泡 - (void)didPressSendButton:(UIButton *)button 等。

- (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];
}
于 2016-03-22T07:13:58.643 回答