JSQMessagesViewController:我的消息没有显示
JSQMessagesViewController : my message doesn't Show up
我的示例项目中有 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;
}
希望对您有所帮助...
我的示例项目中有 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;
}
希望对您有所帮助...