2017-05-25 45 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];