ios - 日期未显示在 JSQMessagesViewcontroller 聊天页面中

标签 ios objective-c jsqmessagesviewcontroller

messageForRow = [[JSQMessage alloc] initWithSenderId:[[DataArray objectAtIndex:indexPath.row] objectForKey:@"UserId"] senderDisplayName:[[DataArray objectAtIndex:indexPath.row] objectForKey:@"Name"] date:[NSDate distantPast] text: [[DataArray objectAtIndex:indexPath.row] objectForKey:@"Message"]];

enter image description here

最佳答案

您需要实现这些方法以使其可见

  - (NSAttributedString *)collectionView:(JSQMessagesCollectionView *)collectionView attributedTextForCellBottomLabelAtIndexPath:(NSIndexPath *)indexPath {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MMM-yyyy"];//22-Nov-2012
NSString *formattedDateString = [dateFormatter stringFromDate:[[DataArray objectAtIndex:indexPath.row] date]];
        return [[NSAttributedString alloc] initWithString:formattedDateString];
     }

    - (CGFloat)collectionView:(JSQMessagesCollectionView *)collectionView
                       layout:(JSQMessagesCollectionViewFlowLayout *)collectionViewLayout heightForCellBottomLabelAtIndexPath:(NSIndexPath *)indexPath {
        return kJSQMessagesCollectionViewCellLabelHeightDefault;
    }

关于ios - 日期未显示在 JSQMessagesViewcontroller 聊天页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37224316/

相关文章:

ios - 旋转 CCSprite Cocos2D?

ios - NSLayoutConstrain - 将尝试通过破坏约束来恢复 - 以编程方式创建约束

ios - JSQMessageData 追加 Json 数据

ios - 如何覆盖 JSQMessagesViewController 中自定义媒体项的 mediaView 显示大小?

ios - Firebase,离开我的调试器控制台

ios - SwiftSpinner 在调用 API 时遇到问题 - swift ios

iOS 检测应用程序已关闭

iphone - 我什么时候应该在 -(void)viewDidUnload 而不是 -dealloc 中释放对象?

ios - "Scene is unreachable due to lack of entry points and does not have..."- 解决这个警告

ios - 'JSQSystemSoundPlayer' 没有可见的@interface 声明选择器 'playSoundWithFilename:fileExtension:'