2017-05-25 33 views
0

我正在申请病人可以与医生聊天。我正在使用firebase来存储和检索数据。但是,每当我尝试发送聊天消息时,该消息都已成功添加到Firebase中,但它不会显示在collectionView的底部(直到我从左侧菜单栏中选择消息按钮)。我正在使用jsqmessages并在objective-c中制作项目。聊天没有显示在收集视图

当按下发送按钮

- (void)didPressSendButton:(UIButton *)button 
     withMessageText:(NSString *)text 
       senderId:(NSString *)senderId 
    senderDisplayName:(NSString *)senderDisplayName 
        date:(NSDate *)date 
{ 
/*** Sending a message. Your implementation of this method should do *at least* the following: 
* 
* 1. Play sound (optional) 
* 2. Add new id<JSQMessageData> object to your data source 
* 3. Call `finishSendingMessage` 
*/ 

if (![_connection isInternet]) { 
    [self noInternetView:@"You can not send messages while you are offline"]; 
    return; 
} 

[JSQSystemSoundPlayer jsq_playMessageSentSound]; 

JSQMessage *message = [[JSQMessage alloc] initWithSenderId:senderId 
             senderDisplayName:senderDisplayName 
                 date:date 
                 text:text]; 

//senderDisplayName = @"You"; 
[self.messages addObject:message]; 
[self finishSendingMessage]; 
NSDateFormatter *formatter=[[NSDateFormatter alloc]init]; 
[formatter setDateFormat:@"hh:mm:ss"]; 
NSString *timeString=[formatter stringFromDate:[NSDate date]]; 

NSDateFormatter *formatter1=[[NSDateFormatter alloc]init]; 
[formatter1 setDateFormat:@"yyyy-MM-dd"]; 

NSString *dateString=[formatter1 stringFromDate:[NSDate date]]; 
NSLog(@"DATE : %@",dateString); 
if(_connection.isInternet) 
{ 
[firebaseMethods saveMessageInfoToFirebase:text date:dateString time:timeString msgFrom:senderId msgTo:@"webAdmin"]; 
[CoreDataMethods saveNewMessageInfoToCoreData:text msgTo:@"webAdmin" msgFrom:senderId date:dateString time:timeString]; 
} 
else 
{ 
    [self showNoInternetMessage]; 
} 
} 

请告诉我什么是jsqmessage工作的重要因素。我如何使Automatically scroll to bottomdisplay send message right away in collection view工作?

请问你是否需要任何额外的信息在评论谢谢你。

回答

0

加入消息到self.messages Array ([self.messages addObject:message];)

添加后,他下面两行:

[self finishSendingMessageAnimated:YES]; 
[self.collectionView reloadData];