聊天没有出现在集合视图中

时间:2017-05-25 09:38:40

标签: objective-c xcode firebase chat jsqmessagesviewcontroller

我正在申请病人可以与医生聊天。我正在使用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工作?

请在评论中询问您是否需要任何额外信息,谢谢。

1 个答案:

答案 0 :(得分:0)

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

添加以下两行:

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