0

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

此图像显示屏幕首次加载的时间。

这张图片显示了我滚动一段时间后的屏幕。

此图像显示消息清晰可见,但气泡未出现。

第一个屏幕截图显示屏幕首次加载的时间。当我移动它时,第二个显示。第三显示其他消息确实存在但不可见。有想法该怎么解决这个吗?另外,如何让名字出现?是否有在 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()
}

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

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
}

}

任何帮助将非常感激!!!

4

1 回答 1

0

You need to call self.finishReceivingMessage() after you add the message(s) to the data source (which will then invalidate layout BEFORE call collectionView.reloadData() for you)

于 2018-03-16T13:29:31.650 回答