gpt4 book ai didi

ios - JSQMessages 显示测试消息的问题

转载 作者:行者123 更新时间:2023-11-30 13:36:02 24 4
gpt4 key购买 nike

当我添加多条测试消息时,屏幕上只显示其中两条。其他消息显然在那里,因为我可以复制它们,但颜色根本不显示。当我滚动时,出现了新的两个文本,但它仍然只有两个。下面显示一些示例。

This image shows when the screen first loads.

This image shows the screen after I've scrolled around for a bit.

This image shows that the messages are clearly there, but that the bubbles are not showing up.

第一个屏幕截图显示了屏幕首次加载的时间。当我移动它时,第二个显示。第三个显示其他消息确实存在但不可见。有想法该怎么解决这个吗?另外,如何让名字出现?在 Swift 中是否有一个很好的指南来做到这一点?

这是我使用的代码:

    var messages = [JSQMessage]()

var incomingBubbleImageView = JSQMessagesBubbleImageFactory.incomingMessageBubbleImageViewWithColor(UIColor.jsq_messageBubbleLightGrayColor())
var outgoingBubbleImageView = JSQMessagesBubbleImageFactory.outgoingMessageBubbleImageViewWithColor(UIColor.jsq_messageBubbleGreenColor())

override func viewDidLoad() {
super.viewDidLoad()

self.sender = UIDevice.currentDevice().identifierForVendor?.UUIDString

messages += [JSQMessage(text: "hello", sender: self.sender)]
messages += [JSQMessage(text: "hello", sender: "other")]
messages += [JSQMessage(text: "hello", sender: self.sender)]
messages += [JSQMessage(text: "hello", sender: "other")]
messages += [JSQMessage(text: "hello", sender: self.sender)]
messages += [JSQMessage(text: "hello", sender: "other")]

reloadMessagesView()

}

func reloadMessagesView() {
self.collectionView?.reloadData()
}

这是委托(delegate)方法的扩展代码:

extension TestJSQ {

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(self.messages.count)
return self.messages.count
}

override func collectionView(collectionView: JSQMessagesCollectionView!, messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! {
let data = self.messages[indexPath.row]
return data
}

//覆盖 func collectionView(collectionView: JSQMessagesCollectionView!, didDeleteMessageAtIndexPath indexPath: NSIndexPath!) {//self.messages.removeAtIndex(indexPath.row)

override func collectionView(collectionView: JSQMessagesCollectionView, bubbleImageViewForItemAtIndexPath indexPath: NSIndexPath) -> UIImageView {

let data = messages[indexPath.row]
switch(data.sender) {
case self.sender:
return self.outgoingBubbleImageView
default:
return self.incomingBubbleImageView
}

}

override func collectionView(collectionView: JSQMessagesCollectionView!, avatarImageViewForItemAtIndexPath indexPath: NSIndexPath!) -> UIImageView! {
return nil
}

}

任何帮助将不胜感激!!!

最佳答案

将消息添加到数据源后,您需要调用 self.finishReceivingMessage() (这将在调用 collectionView.reloadData() 之前使布局无效) > 为你)

关于ios - JSQMessages 显示测试消息的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36058312/

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