gpt4 book ai didi

ios - 为 JSQMessages 添加名称标签和日期标签

转载 作者:搜寻专家 更新时间:2023-11-01 06:40:14 24 4
gpt4 key购买 nike

我正在尝试将 topLabel 添加到 JSQMessageCollectionViewCell 并正在实现正确的方法,但没有显示任何内容。这是我的代码:

override func collectionView(collectionView: JSQMessagesCollectionView!, attributedTextForMessageBubbleTopLabelAtIndexPath indexPath: NSIndexPath!) -> NSAttributedString! {

let msg: JSQMessage = self.JSQmessages[indexPath.item]
if (msg.senderId != self.senderId) {

return NSAttributedString(string: "Tester")
}
else {
return NSAttributedString(string: senderDisplayName)
}

}

此外,我正在尝试通过点击给定的消息收集单元格来添加日期标签。我应该怎么做呢?我正在添加一个 NSDate 作为每个 JSQMessage 的一部分。

最佳答案

您需要通过实现返回顶部标签的高度:

- (CGFloat)collectionView:(JSQMessagesCollectionView *)collectionView
layout:(JSQMessagesCollectionViewFlowLayout *)collectionViewLayout heightForCellTopLabelAtIndexPath:(NSIndexPath *)indexPath;

为了在点击时显示标签,您需要存储所选的 indexPath,并在上述方法中返回该 indexPath 的高度。

关于ios - 为 JSQMessages 添加名称标签和日期标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36384904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com