gpt4 book ai didi

ios - JSQMessagesViewController : my message doesn't Show up

转载 作者:行者123 更新时间:2023-11-28 21:10:55 25 4
gpt4 key购买 nike

我的示例项目上有 JSQMessageViewController,抱歉,这是我第一次使用它,这意味着基本上我是新手,当我运行我的项目并键入消息并单击发送时,我的消息没有显示

我的 .h 文件

    //
// 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 文件

    //
// 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

非常感谢

最佳答案

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

//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;
}

希望对你有帮助

关于ios - JSQMessagesViewController : my message doesn't Show up,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43309177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com