首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSQMessagesViewController :我的留言没有出现

JSQMessagesViewController :我的留言没有出现
EN

Stack Overflow用户
提问于 2017-04-09 16:34:40
回答 1查看 317关注 0票数 0

我的示例项目上有JSQMessageViewController,对不起,这是我第一次使用它,这意味着我对此基本上是新手,当我运行我的项目时,当我键入一条消息并单击send,我的消息就不会出现。

我的.h文件

代码语言:javascript
复制
    //
//  ViewController.h
//  JsqSimple
//
//  Created by Rawand Ahmed Shaswar on 4/9/17.
//  Copyright © 2017 ABA Group. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <JSQMessagesViewController/JSQMessages.h>

@interface ViewController : JSQMessagesViewController {

}

@end

而且,

我的.m文件

代码语言:javascript
复制
    //
//  ViewController.m
//  JsqSimple
//
//  Created by Rawand Ahmed Shaswar on 4/9/17.
//  Copyright © 2017 ABA Group. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.senderDisplayName = @"Fiko";
    self.senderId = @"Erick";

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void) didPressSendButton:(UIButton *)button withMessageText:(NSString *)text senderId:(NSString *)senderId senderDisplayName:(NSString *)senderDisplayName date:(NSDate *)date {
    self.senderId = senderId;
    self.senderDisplayName = senderDisplayName;
    [JSQMessagesViewController messagesViewController];
    [self finishSendingMessage];
}

@end

非常感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-10 03:22:49

要显示文本--类似于ios消息--您可以这样做

代码语言:javascript
复制
//Array to keep the text's
NSMutableArray *message=nil;

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

    //creating the message object with message;
    JSQMessage *me=[[JSQMessage alloc]initWithSenderId:senderId senderDisplayName:senderDisplayName date:[NSDate distantPast] text:text];

    //initializing the array if its first time
    if(message==nil){
        message=[[NSMutableArray alloc]init];
    }
    //adding message to array 
    [message addObject:me];

    //Reloading the collectionView to get the update
    [self.collectionView reloadData];

}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    NSLog(@"number of message:%lu",(unsigned long)[message count]);
    // counting & returning total number of message
    return [message count];

}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *)[super collectionView:collectionView cellForItemAtIndexPath:indexPath];

    return cell;
}
-(id<JSQMessageData>)collectionView:(JSQMessagesCollectionView *)collectionView messageDataForItemAtIndexPath:(NSIndexPath *)indexPath{

    return message[indexPath.item];
}

-(id<JSQMessageBubbleImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView messageBubbleImageDataForItemAtIndexPath:(NSIndexPath *)indexPath{

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

//You can change the  bubble color here
    return [bubbleFactory outgoingMessagesBubbleImageWithColor:[UIColor greenColor]];
}

-(id<JSQMessageAvatarImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView avatarImageDataForItemAtIndexPath:(NSIndexPath *)indexPath{
    return nil;
}

希望能帮上忙..。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43309177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档